Was*_*ama 6 c++ pointers visual-c++
运行时为什么会出错?我期待ptr_ref无法修改ptr指向的地址,但事情似乎没有按计划进行.
int b = 3;
int* ptr = &b;
//says something about cannot convert int* to type const int*&
const int*& ptr_ref = ptr;
Run Code Online (Sandbox Code Playgroud)
在此先感谢,15岁的C++ noob
Bri*_*ian 11
ptr_ref
声明不是const
对指针的引用int
,而是对指针的引用const int
,因此您的类型不匹配.你必须这样做
int* const& ptr_ref = ptr;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
552 次 |
最近记录: |