多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
~~~ #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; } ~~~