企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[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/>