【发布时间】:2020-04-25 15:06:03
【问题描述】:
int main()
{
int n = 1;
int* const p = &n; // ok
*p = 2; // ok as expected.
p = 0; // error as expected.
int& const m = n;
// error: 'const' qualifier may not be
// applied to a reference
return 0;
}
为什么在 C++ 中没有 const 引用,就像 const 指针一样?
设计背后的基本原理是什么?
【问题讨论】:
-
您认为
const限定符会阻止您做什么?
标签: c++ pointers reference constants standards