开发者

Define default constructor for abstract base class

class ClassA {
public:
    ClassA() {} // when this function must be provided
    virtual ~ClassA() = 0 {}
};

class ClassB : public ClassA
{
    // ...        
};

I want to know 开发者_Go百科when the default constructor of an abstract base class must be provided.


there is no connection between providing a default constructor, and the abstractness or not of the class.

provide a default constructor definition if you need to initialize things.

provide a (possibly non-implemented) non-public declaration if you want to prohibit default construction.

cheers & hth.,


If it is truly an abstract base class with no data members, the compiler-generated constructor will be totally sufficient in every case.

The derived classes will always call the default base class constructor unless their constructor specifies a different one in the initializer list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜