C++: any way to prevent any instantiation of an abstract base class?

后端 未结 3 614
我在风中等你
我在风中等你 2021-02-19 01:19

Aside from having a pure virtual function, is there a way to prevent an instantiation of an abstract base class?

I can do this:

class BaseFoo
{
    virtu         


        
3条回答
  •  滥情空心
    2021-02-19 01:41

    A really obvious way is to declare a protected constructor, and to declare public constructors in the non-abstract derived classes.

    This of course shifts the burden of corectness to the derived classes, but at least the base class is protected.

提交回复
热议问题