💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[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/>