我有一个基类,它声明和定义了一个构造函数,但出于某些原因,我的公共派生类没有看到那个构造函数,因此我不得不在派生类中明确声明一个转发构造函数:
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)
。