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://www.cnblogs.com/Stephen-Qin/p/13412293.html