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
限定符会阻止你做什么? - Nate Eldredge