感觉有意思,大家共享解决思路
感觉有意思,大家共享
//例4
//程序作者:管宁
//站点:www.cndev-lab.com
//所有稿件均有版权,如要转载,请务必著名出处和作者
#include <iostream>
using namespace std;
class Test
{
public:
Test(int a = 0)
{
cout < <this < < ": " < < "载入构造函数! " < <a < <endl;
Test::a = a;
}
Test(Test &temp)
{
cout < < "载入拷贝构造函数! " < <endl;
Test::a = temp.a;
}
~Test()
{
cout < <this < < ": " < < "载入析构函数! " < <this-> a < <endl;
cin.get();
}
Test operator +(Test& temp2)
{
cout < <this < < "| " < <&temp2 < < "载入加运算符重载函数! " < <endl;
Test result(this-> a+temp2.a);
return result;
}
operator int()
{
cout < <this < < ": " < < "载入转换运算符函数的内存地址: " < <this-> a < <endl;
return Test::a;
//例4
//程序作者:管宁
//站点:www.cndev-lab.com
//所有稿件均有版权,如要转载,请务必著名出处和作者
#include <iostream>
using namespace std;
class Test
{
public:
Test(int a = 0)
{
cout < <this < < ": " < < "载入构造函数! " < <a < <endl;
Test::a = a;
}
Test(Test &temp)
{
cout < < "载入拷贝构造函数! " < <endl;
Test::a = temp.a;
}
~Test()
{
cout < <this < < ": " < < "载入析构函数! " < <this-> a < <endl;
cin.get();
}
Test operator +(Test& temp2)
{
cout < <this < < "| " < <&temp2 < < "载入加运算符重载函数! " < <endl;
Test result(this-> a+temp2.a);
return result;
}
operator int()
{
cout < <this < < ": " < < "载入转换运算符函数的内存地址: " < <this-> a < <endl;
return Test::a;