标签:
#include <iostream>
using namespace std;
class ClassTest
{
public:
ClassTest()
{
cout << "ClassTest()" <<endl;
}
ClassTest(int i)
{
cout << "ClassTest(int)" <<endl;
value2 = i;
}
ClassTest(int i, int j): value(i), value2(j)
{
cout << "ClassTest(int, int)" <<endl;
}
private:
int value = 0;
int value2 = 0;
};
int main()
{
ClassTest test;//使用默认构造函数(即ClassTest())
//ClassTest test();/*这里被认为是一个函数的声明,而不是定义对象*/
ClassTest test1(1);//ClassTest(int)
ClassTest test2(1, 2);//ClassTest(int, int)
ClassTest test3 = ClassTest(); //先调用ClassTest()构建一个临时变量,然后将这个临时变量通过拷贝构造函数赋值给test3
return 0;
}
int main()
{
ClassTest * pClass = new ClassTest;
ClassTest * pClass1 = new ClassTest();
ClassTest * pClass2 = new ClassTest(1);
ClassTest * pClass3 = new ClassTest(1, 2);
delete pClass;
delete pClass1;
delete pClass2;
delete pclass3;
return 0;
}
标签:
原文地址:http://www.cnblogs.com/fengkang1008/p/4652255.html