Search code examples
c++abstract-classvirtual-destructor

Declare and implement pure virtual destructor in one line?


I am making a pure virtual destructor to force a class to be abstract that contains no methods apart from the ctor. I am doing this as a header-only implementation

struct abstractSchema
{
    abstractSchema(...): ... { ... }
    virtual ~abstractSchema() = 0;    
};
inline abstractSchema::~abstractSchema(){}

Is there any syntactic sugar like (the illegal) virtual ~abstractSchema(){} = 0; that would allow me to declare and define on a single line, rather than having to split the definition and implementation like in the above example?


Solution

  • This is as close as you can get:

    struct abstractSchema
    {
        virtual ~abstractSchema(){}
        protected: abstractSchema(...): ... { ... }
    };
    

    It's not abstract, but it can't be instantiated by itself so might meet your needs.