企业🤖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; } ~~~