const成员函数和const对象待整理.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// int main()
// {
// const int n = 1;
// auto ptr = (int*)(&n);
// *ptr = 2;
// cout << n;
// }
class A
{
public:
int getA()
{
return a;
}
int getCA() const
{
return a;
}
private:
const int a = 1;
};
int main()
{
A a;
int b = a.getA(); //a can only call const fun.
cout << b;
return 0;
}
新战场:https://blog.csdn.net/Stephen___Qin