#include
using namespace std;
class Test
{
public:
//Test(),Test(10),Test(10,20)
Test(int a = 10, int b = 20)
{
ma = a; mb = b;
cout << "Test(int,int)" << endl;
}
Test(const Test& test)
{
ma = test.ma;mb = test.mb;
cout << "Test(const Test&)" << endl;
}
void operator=(const Test& t )
{
ma = t.ma;mb = t.mb;
cout << "operator=()" << endl;
}
~Test()
{}
private:
int ma, mb;
};
Test t1(10, 10);//1.Test(int,int)
//局部静态变量,static Test t4,程序执行到定义地点,
//t4才开始初始化,程序结束时,t4才析构.
int main()
{
Test t2(20, 20);//3.Test(int,int)
Test t3 = t2;   //4.Test(const Test&)
//=static Test t4(30,30).Test(30, 30)不会生成临时对象不会调用构造函数,被优化掉了.
static Test t4 = Test(30, 30);//5.Test(int,int)
t2 = Test(40, 40);//6.Test(int,int),operator=(),~Test()
//(50,50)逗号表达式,值为50.等价于(Test)50.
t2 = (Test)(50, 50);//7.Test(int,int),operator=(),~Test()
t2 = 60;//8 Test(int),operator=(),~Test(),隐式转换.
Test* p1 = new Test(70, 70);//9.Test(int,int)
Test* p2 = new Test[2];//10.Test(int,int),Test(int,int)
//const Test* p3 = &Test(80, 80);//11编译不通过.
const Test& p4 = Test(90, 90); //12.Test(int,int)
delete p1;//13.~Test()
delete[]p2;//14.~Test(), ~Test()
}
Test t5(100, 100);//2.Test(int,int)