霸气外泄的const

来源:互联网 发布:fake it til make it 编辑:程序博客网 时间:2024/06/10 03:01
#include<iostream>
using namespace std;
int main()
{
const int a = 10;
cout << a << endl;
a = a + 1;
cout << a;
return 0;

}

错误 1 error C3892: “a”: 不能给常量赋值

2 IntelliSense:  表达式必须是可修改的左值.

原因是a是被限制死了的变量,前面加了const int a =10;不是int a =10;

加了const后这个是时候可以理解a为常量了。

0 0