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
{
virtual void blah() = 0;
};
class Foo : public BaseFoo
{
virtual void blah() {}
};
but I'd like to avoid a vtable. (as per my other question about virtual destructors)
Microsoft ATL has ATL_NO_VTABLE to accomplish this (or at开发者_JAVA技巧 least I think that's what it does...)
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.
You could make a protected constructor
精彩评论