【发布时间】:2010-01-16 05:46:55
【问题描述】:
class TestClass
{
public:
TestClass(int i) { i = i; };
private:
int i;
}
class TestClass2
{
private:
TestClass testClass;
}
为什么即使我们没有提供默认构造函数,上面的代码也能正常编译?
只有当有人在代码的其他地方实例化 TestClass2 时,我们才会收到编译错误。编译器在这里做什么?好像很奇怪……
谢谢。
【问题讨论】:
-
如果我是你,我会避免使用相同的参数作为方法的参数和对象的属性......你会遇到奇怪的错误。
标签: c++ compiler-construction constructor default