//如果形参a,和类的属性a是相同的,就没法赋值,可以通过this指针进行操作
#include<iostream>
using namespace std;
class test
{
private:
int a;
int b;
public:
test(int a,int b)//->test(test *this,int a,int b)
{
this->a =a;
this->b =b;
}
void printt()
{
cout<<"a "<<a<<" b "<<this->b <<endl;
}
protected:
};
int main()
{
test t1(10,20);
t1.printt() ;//===>printt(&t1)
cout<<"hello"<<endl;
return 0;
}
C++中this指针最基础的用法
C++中this指针最基础的用法如果形参 a 和类的属性 a 是相同的 就没法赋值 可以通过 this 指针进行操作 include iostream using namespace std class test private int a int b public test int a int b gt test test this int a iostream
大家好,我是讯享网,很高兴认识大家。
第一讲——什么是计算机网络?
上一篇
2025-02-23 20:51
java开发插件
下一篇
2025-03-20 18:52

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/74765.html