#include<iostream>
using namespace std;
class test
{
public:
//const修饰this指针 即指针所指向的内存空间
//所以this->a,this->b一旦被修改就会报错
void play(int a,int b) const
{
a = 100;//编译没有错误,即const修饰的不是该函数的形参
//this->a = 100;//编译产生错误
//this->b = 200;//产生错误
}
private:
int a;
int b;
};
int main()
{
test t1;
t1.play(1,2);
system("pause");
}
C++ const修饰this指针
猜你喜欢
转载自blog.csdn.net/error0_dameng/article/details/82078646
今日推荐
周排行