如何实现此行为?在另一个类中声明一个具有非默认构造函数的类
class A
{
int x;
public:
A(int x) : x(x) {}
};
class B
{
A a; // here is the problem
public:
B() : a(1) {} // solution i found
};
int main(void)
{
B b;
return 0;
}
我想知道是否有另一种方式使这项工作,除了我发现的答案。
注意:一个构造函数可以接受单个参数通常更好地标记为“显式”。 – 2012-07-05 17:26:56