![]() |
#2
ly8610142009-08-23 22:51
|

#include <iostream>
using namespace std;
class Test
{
public:
Test(int a = 0)
{
cout<<this<<":"<<"载入构造函数!"<<a<<endl;
Test::a = a; //这是什么意思???a不是已经在类中吗?干嘛还这样写,还有就是我为什么不把Text::a改写成M之类的字母呢?
}
Test(Test &temp)
{
cout<<"载入拷贝构造函数!"<<endl;
Test::a = temp.a;
}
~Test()
{
cout<<this<<":"<<"载入析构函数!"<<this->a<<endl;
cin.get();
}
operator int()
{
cout<<this<<":"<<"载入转换运算符函数的内存地址:"<<this->a<<endl;
return Test::a;
}
public:
int a;
};
int main()
{
Test a(100),b(100),c;
cout<<"a的内存地址"<<&a<<" | b的内存地址"<<&b<<endl;
c=Test((int)a+(int)b);//显示式转换
//c=a+b;//隐式转换
cout<<"c的内存地址"<<&c<<endl;
cout<<c.a<<endl; //c.a又是什么意思?? system("pause");
}
using namespace std;
class Test
{
public:
Test(int a = 0)
{
cout<<this<<":"<<"载入构造函数!"<<a<<endl;
Test::a = a; //这是什么意思???a不是已经在类中吗?干嘛还这样写,还有就是我为什么不把Text::a改写成M之类的字母呢?
}
Test(Test &temp)
{
cout<<"载入拷贝构造函数!"<<endl;
Test::a = temp.a;
}
~Test()
{
cout<<this<<":"<<"载入析构函数!"<<this->a<<endl;
cin.get();
}
operator int()
{
cout<<this<<":"<<"载入转换运算符函数的内存地址:"<<this->a<<endl;
return Test::a;
}
public:
int a;
};
int main()
{
Test a(100),b(100),c;
cout<<"a的内存地址"<<&a<<" | b的内存地址"<<&b<<endl;
c=Test((int)a+(int)b);//显示式转换
//c=a+b;//隐式转换
cout<<"c的内存地址"<<&c<<endl;
cout<<c.a<<endl; //c.a又是什么意思?? system("pause");
}