以下几种初始化方式有什么不同呢?
不知注释中的理解是否正确?
class CExample {
private:
int a;
public:
CExample(int b)
{
a = b;
}
CExample(const CExample& b)
{
a = b.a;
}
void Show()
{
cout << a << endl;
}
};
//1.test1 被初始化,执行默认构造函数,在栈上定义
CExample test1;
//2. test1 被初始化,执行默认构造函数,在栈上定义。
CExample test1 = CExample();
//3. test1被初始化,在堆上定义。 与CExample* test1 = new CExample;是否相同?
CExample* test1 = new CExample();