仅仅是测试一下,当函数返回类型为一个类时的情况。 #include<iostream> using namespace std; class A { public: int i; int *n; A() // 构造函数 { n= new int; *n = 101; } ~A() // 析构函数 { cout<<"Destructor"<<'/t'<<*n<<endl; cout<<this<<endl; delete n; } A& operator =(const A& a) { cout<<"Copy"<<endl; if(this == &a) return *this; this->i = a.i; *(this->n) = *(a.n); return *this; } void print() { cout<<i<<endl; cout<<*n<<endl; } }; A GetA() { A a; a.i =3000; *(a.n)=3001; return a; } int main() { A *a = new A(); *a = GetA(); a->print(); delete a; }