Normall const variable:
Your can’t change it even if you defined a variable as a const
Int const x = 2 or const int x = 2
Const object :
Const Dog mimi or Dog const mimi
Const pointer and refer
char * const prt1 = string prt1; ---- a const pointer to a string
it is wrong that give prt1 the value like ptr1 = string prst2 , you can use *prt1 = “m”
but
const * ptr2 = string prt1;
*prt2 = “x” is wrong prst2 = stirng prt1 is ok
const double & v;
Const function :
Only constf function can operate const variable
void R::print() const
{
cout<<R1<<";"<<R2<<ENDL;
}
本文详细解析了C++中常量(const)的概念及其用法,包括常量变量、常量对象、常量指针及引用的定义与使用限制,并介绍了常量成员函数的特性。

被折叠的 条评论
为什么被折叠?



