🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## 参数与成员变量重名 可使用 `this->` 做处理 ``` class A { public: int a; void setData(int a) { this->a=a; }; void getData() { cout << this->a<< endl; }; }; ``` ## 判断一个对象是否为自己 <details> <summary>main.cpp</summary> ``` #include <iostream> #include <string> using namespace std; class A { public: bool check(A *obj) { if (obj == this) { cout << "is self" << endl; } else { cout << "is not self" << endl; } } }; class B :public A { public: A *getBase() { A *p = this; return p; } }; int main() { A a; B b; A *p1 =&a; A *p2=b.getBase(); a.check(p1); a.check(p2); return 0; } ``` </details> <br/> 输出 ``` is self is not self ``` ## 运算符重载 <details> <summary>main.cpp</summary> ``` ``` </details> <br/>