Abstract class cannot instantiate instance given pure virtual function exists.
Pure virtual function: you can define and invoke pure virtual function, but it can be only invoked statically rather than via virtual mechanism.
Do NOT declare a pure virtual destructor: compiler will expand every derived class destructor, statically invoke all virtual base class destructors and base class destructors. So absence of one base class destructor will fail the link.
// before
class Abstract_base
{
public:
virtual ~Abstract_base() = 0;
virtual void interface() const = 0;
virtual const char* mumble() const { return _mumble;}
protected:
char* _mumble;
}
// it should be
class Abstract_base
{
public:
virtual ~Abstract_base();
virtual void interface() const = 0;
const char* mumble() const { return _mumble;}
protected:
Abstract_base(char* pc = 0);
char* _mumble;
}
1. Construction without inheritance
For global variable:
- C consider it is a temporary definition without initialization, and it will be stored in a space for those "uninitialized global objects".
- C++ does NOT support temporary definition, it will be considered as an initialized global object.
Explicit initialization list will be a bit more efficient than inline expansion of constructor.
2. Construction in inheritance chain
3. Object copy semantics
4. Object efficiency
5. Semantics of Destruction