
const int SIZE = 20;
const int* p = &a; *p = 10; // 错❌️ p = &b; // 对✅️
int* const p = &a; *p = 10; // 对✅️ p = &b; // 错❌️
const int* const p = &a;
void printData(const std::string& str) { }
class Student {
private:
mutable int cache_hits; // 即使const函数也可以改
int age;
public:
// const成员函数内,this被隐式视为 const Student* const this
int getAge() const {
// age = 10; // ❌ 编译报错
cache_hits++; // ✅ 允许,因为mutable
return age;
}
};
const Student& getStudent() { return stu; } // 返回引用防修改
const int getValue() { return 1; } // 防止 (a = getValue()) = 3 这样的左值赋值操作
Python工程实践之np.loadtxt()读取数据
python中的extend功能及用法
pythonJieba分词处理详解【模式词库的添加、删除自定义词库失败处理等】
pycharm没有找到manage repositories按钮的解决办法
Python+pandas数据分析实践总结
pycharm中报ModuleNotFoundErrorNo module named apostensorflowapos错误解决