?????μ???????????????????
???????c++??????????const?????????
????1.??????this?????const ?????????????
????2.const ???????????????????????????????
????(static??????????const???η???const ????????????this??????????????static????????)
????3.const ????????????????????????????
????4.const ?????????????÷?const ???????
????????????const??????const???????????????
????1.??const ?????????????????? const????
????2.const?????????????????????????ù????const????
????1-1

//error C2662: “Text::print”: ?????“this”????“const Text”????“Text &”
#include "stdafx.h"
#include "iostream"
using namespace std;
class Text{
public:
void printconst(void)const{cout<<"hello"<<endl;}
void print(void){cout<<"hello"<<endl;}
private:
int k;
};
//???漲??????Text???????????
int main(void)
{
a.printconst(); //ok
a.print();      //error
//????a.print()??????????
return 0;
}
????1-2
//error C2272: “printconst”: ????????????????????η?
#include "stdafx.h"
#include "iostream"
using namespace std;
class Text{
public:
void static printconst(void) const{cout<<"hello"<<endl;}
void print(void){cout<<"hello"<<endl;}
private:
int k;
};
int main(void)
{
Text a;
a.printconst();
return 0;
}