ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ #include <iostream> using namespace std; class Person { public: Person(int param) { this->mParam = param; } void PrintPerson() { cout << "Param: " << mParam << endl; } private: int mParam; }; class SmartPointer{ public: SmartPointer(Person* person){ this->pPerson = person; } //重载指针的->、*操作符 Person* operator->(){ return pPerson; } Person& operator*(){ return *pPerson; } ~SmartPointer() { if (pPerson != NULL) { delete pPerson; } } public: Person *pPerson; }; void test01() { SmartPointer pointer(new Person(100)); pointer->PrintPerson(); } int main() { test01(); getchar(); return EXIT_SUCCESS; } ~~~