【发布时间】:2018-08-07 01:05:18
【问题描述】:
目前的结构类似于
class B {
//no default constructor
//this is a class in a third-party library, can't be modified
B(Lots ofData, AndOther arguments);
}
class A {
B b;
A(some_parameters){
//Do a lot of stuff with those parameters, make Results
B b(Results, Results); //ERROR
}
}
所以,我需要在B 上调用构造函数,但我没有足够早的信息在初始化列表中执行此操作。以后如何在B 上调用构造函数?因为B 没有简单的构造函数,所以我不能用一些愚蠢的默认值完全初始化并在以后覆盖它。
我无法更改 B 类。
【问题讨论】:
-
你遇到了什么编译错误?
-
@Bill 上面的代码(几乎)可以编译,但它声明了两次
b。我试图说明我想做什么(如果它没有重新声明它)。它实际上并没有编译,因为B没有默认构造函数。
标签: c++ class constructor initialization