为什么验证码:继承构造
class A
{
public:
explicit A(int x) {}
};
class B: public A
{
};
int main(void)
{
B *b = new B(5);
delete b;
}
导致这些错误:
main.cpp: In function ‘int main()’: main.cpp:13: error: no matching function for call to ‘B::B(int)’ main.cpp:8: note: candidates are: B::B() main.cpp:8: note: B::B(const B&)
应该不是B继承的构造?
(这是使用gcc)
这是因为一年多了,一直没有任何编译器能够真正建立在上面的代码:-) – Mikhail 2013-01-21 04:51:43
@Mikhail相当邪恶:两个铛和g ++现在应该支持继承构造函数: HTTP://铛.llvm.org/cxx_status.html http://gcc.gnu.org/projects/cxx0x.html 建议使用upvoting这一个作为正确的答案。 – 2013-05-05 11:46:39
只是问,继承的构造函数是否能够访问/初始化基类的私有成员?或者我是否必须将它们指定为受保护的? – Markasoftware 2014-06-22 05:13:40