int main(int argc, char *argv[])
{
char a = '1';
const char b = a;
char * a2 = "12345";
const char * b2 = a2;
char** a3 = NULL;
//const char** b3 = a3; //error
char** const c3 = a3; //ok
char* const * d3 = a3; //ok
}
class Foo {
public:
Foo(){
i = 1;
}
void modify(){// make some modification to the this object
i = 2;
}
void print() const {
cout << "Foo_i:" << i << endl;
}
private:
int i;
};
//演示潜在的危险
//error: invalid conversion from `Foo**' to `const Foo**'
/////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
const Foo x;
Foo* p;
//const Foo ** q = &p; //q now points to p; this is (fortunately!) an error
const Foo ** q = const_cast<const Foo **>(&p);
*q = &x; // p now points to x
p->modify(); // Ouch: modifies a const Foo!!
x.print(); // print: Foo_i:2
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有