源代码1:
#include "stdafx.h"
#include <iostream>
using namespace std;
class A
{
public:
A()
{
cout << "In A(): " << hex << (long)this << endl;
}
A(const A&)
{
cout << "In A(const A&): " << hex << (long)this << endl;
}
~A()
{
cout << "In ~A(): " << hex << (long)this << endl;
}
A& operator=(const A& a)
{
cout << "In operator=: " << hex << (long)this << " = " << hex << (long)(&a) << endl;
return *this;
}
};
A f()
{
A a;
return a;
}
int _tmain(int argc, _TCHAR* argv[])
{
A a;
a = f();
return 0;
}
源代码2:
// test1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class A
{
public:
A()
{
cout << "In A(): " << hex << (long)this << endl;
}
A(const A&)
{
cout << "In A(const A&): " << hex << (long)this << endl;
}
~A()
{
cout << "In ~A(): " << hex << (long)this << endl;
}
A& operator=(const A& a)
{
cout << "In operator=: " << hex << (long)this << " = " << hex << (long)(&a) << endl;
return *this;
}
};
A f()
{
A a;
return a;
}
int _tmain(int argc, _TCHAR* argv[])
{
A a=f();
return 0;
}