#include<iostream> using namespace std; class A { public: void f(){cout<<"A"<<endl;} }; class B { public: B():pa(new A){} A* Get() { return pa; } ~B(){delete pa;} private: A* pa; }; int main() { B b; b.Get()->f(); return 0; }