1.
–Base-pointer to base-object, derived-pointerto derived
•Straightforward
–Base-pointer to derived object
•Can only call base-class functions(
But if thebase class function isdeclared virtual, then the derivedclass version can be called.)
–Derived-pointer to base-object
•Compiler error
•Allowed if explicit cast made (more insection 10.9)
2.
Abstract class
–Sole purpose: to be a base class (called abstract base classes)
–Incomplete
•Derived classes fill in "missingpieces"
–Cannot instantiate objects from an abstract class
•However, can have pointers and references toclass.
–Need one or more "pure" virtualfunctions
virtual void draw() const =0;
–Pure virtual functions
•No implementation, must be overridden, we can provide a definition for pure virtual function, but still we have to provide a new version for each derived class.
Can't be substantiated, but can create pointer or reference to it. Have no constructor and a virtual destructor.
3. class A
class B : public class A
A a;
B b;
a = b;//ok, but have slicing problem
b = a; // error, because derived class is a base class but base class is not a derived class
It is the same situation when use pointer and reference;