【发布时间】:2011-01-24 11:59:25
【问题描述】:
关于受保护构造函数的一个问题。我了解到受保护的构造函数可以在派生类中使用。但是,我发现下面的代码有错误。为什么会这样?
class A
{
protected:
A(){}
};
class B: public A {
public:
B() {
A* f=new A(); // Why it is not working here
}
};
【问题讨论】:
-
通常发布错误消息会有所帮助:-)。
-
请注意,Clang 3.0 接受此代码。 GCC 4.6 和 4.7 没有。
-
@KristianSpangsege 这是 Clang 中的一个错误,在最近的版本中已修复
标签: c++ constructor protected