5 常量引用
const type &p = q;
常量引用代表不能通过引用去修改引用标识的那块空间
1 #include <iostream>
2 using namespace std;
3 void test01()
4 {
5 int a = 10;
6 // const修饰的是引用& 不能通过引用去修改引用的这块空间的内容
7 const int &b = a;
8 //b = 1000;//err
9 }
10
11 void test02()
12 {
13 //int &b = 100;//不能引用常量
14 const int &b = 1;//int tmp =1 ,const int &b= tmp
15
16 }
17 int main()
18 {
19
20 return 0;
21 }
c++中常量的引用
于 2023-11-29 20:51:35 首次发布