我有一个声明和定义构造函数的基类,但由于某种原因,我的公共派生类没有看到该构造函数,因此我必须在派生类中显式声明一个转发构造函数:
class WireCount0 {
protected:
int m;
public:
WireCount0(const int& rhs) { m = rhs; }
};
class WireCount1 : public WireCount0 {};
class WireCount2 : public WireCount0 {
public:
WireCount2(const int& rhs) : WireCount0(rhs) {}
};
int dummy(int argc, char* argv[]) {
WireCount0 wireCount0(100);
WireCount1 wireCount1(100);
WireCount2 wireCount2(100);
return 0;
}
在上面的代码中,我的WireCount1 wireCount1(100)
声明被编译器拒绝(“No matching function for call to 'WireCount1::WireCount1(int)'”),而我的wireCount0
和wireCount2
声明很好。
我不确定我是否理解为什么需要提供中所示的显式构造函数WireCount2
。是因为编译器为 生成了默认构造函数WireCount1
,而该构造函数隐藏了WireCount0
构造函数吗?
作为参考,编译器是i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5659)
.