Item 33. Manufacturing Abstract Bases
Abstract base categories describe an abstract concept of a problem that cannot be instantiated. Class abc {public: virtual ~ abc (); virtual void Anoperty () = 0; // pure // ...}; a pure virtual function in a class becomes an abstract class, the compiler guarantees that ABC cannot Instantiate.
Sometimes a class does not have a candidate pure virtual function, but I want it to be instantiated, how to do?
1. Constructor and copy constructor declaration to protect member class abc {public: virtual ~ abc (); protected: abc (); abc (const abc&); //...}; Class D: public ABC {/ / ...};
2, declare the destructor as a pure virtual function and provide its implementation class ABC {public: Virtual ~ abc () = 0; // ...}; // ... ABC :: ~ abc () {. ..}
3. When a class does not have a virtual function, there is no need to explicitly declare the constructor, declare the non-false argument function as a protective class abc {protected: ~ abc (); public: // ...} ;