C++ 强制类型转换

摘要: 以下所有的cast 都不会作用于对象本身。只是返回相应的类型的对象。 1、const_cast<新类型>(表达式) const_cast 可用于转型掉(移除)常量性或易变性。 1)两个指向同一类型的多级指针可以相互转换,无关每个层级的cv (const\volidate) 限定符号。 注意: 2) 阅读全文
posted @ 2020-11-02 16:20 Smarc 阅读(175) 评论(0) 推荐(0)

C++----有关const使用

摘要: 1、类的成员函数加上const 类的成员函数后面加上const struct type { int i; type(): i(3) {} void f(int v) const { // this->i = v; // 编译错误:this 是指向 const 的指针 const_cast<type* 阅读全文
posted @ 2020-11-02 10:35 Smarc 阅读(142) 评论(0) 推荐(0)