Is it wrong to write:
class A {
public:
virtual ~A() = 0;
};
for an abstract base class?
At least that compiles in MSVC... Will it crash at run time?
Is it wrong to write:
class A {
public:
virtual ~A() = 0;
};
for an abstract base class?
At least that compiles in MSVC... Will it crash at run time?
Private destructors: they will give you an error when you create an object of a derived class -- not otherwise. A diagnostic may appear though.
A class with a pure virtual destructor is an abstract class. Note well:
Taken straight from the draft:
Yes. You also need to implement the destructor:
should suffice.
And since this got a down vote, I should clarify: If you derive anything from A and then try to delete or destroy it,
A
's destructor will eventually be called. Since it is pure and doesn't have an implementation, undefined behavior will ensue. On one popular platform, that will invoke the purecall handler and crash.Edit: fixing the declaration to be more conformant, compiled with http://www.comeaucomputing.com/tryitout/