The base class performs dynamic binding by adding the keyword virtual before the declaration statement of its member function. A non-static function other than any constructor can be a virtual function. Keyword virtual can only appear within a class of declaration statements and cannot be used for function definitions outside of a class. If the base class declares a function as a virtual function, the function is implicitly also a virtual function in a derived class.
static types and dynamic types
The static type of an expression is always known at compile time. It is the type or expression generated by the variable declaration, and the dynamic type is the type of the object in memory represented by the variable or expression. Dynamic types are unknown until run time.
There is no implicit type conversion from the base class to the derived class
If the base class contains one or more virtual functions, we can request a type conversion using dynamic_cast, and the security check for that transformation will be performed at run time. Similarly, if we know that a base class conversion to a derived class is safe, we can use static_cast to force the overwrite of the compiler's check work.
No type conversions exist between objects
When we pass a derived class object to the constructor of a base class, the one that is defined in the base class when the actual constructor is run, it is clear that the constructor can only handle its own members of the base class. Similarly, if we assign a derived class object to a base class object, the actual run assignment operator is also the one defined by the base class, and the operator can only handle its own members.
classes that contain pure virtual functions are abstract base classes
Classes that contain (or do not overwrite direct inheritance) pure virtual functions are abstract base classes. The abstract base class is responsible for defining the interface, and then the other classes can overwrite the interface. We cannot (directly) create an object of an abstract base class.
Protected Members
1. Similar to private members, protected members are inaccessible to users of the class.
2. Similar to public members, protected members are accessible to members of derived classes and friends. In addition, there is another important property of protected.
3. A member or friend of a derived class can access a protected member of a base class only through a derived class object. A derived class does not have any access privileges to a protected member in a base class object.