The access features of the inherited feature subclass of the parent class.
Public
Protected public protected
Private no access
Public protected
Protected
Private no aceess
Public Private
Protected private
Private no access
Function overloading occurs in a class, and function overwriting occurs between the parent class and the subclass.
When a Member is not a static member, the subclass can use a: function () to access the function of A, and the: B member can also. A Indicates the parent class name.
C ++ polymorphism: When the C ++ compiler finds that its parent class is a virtual function during compilation, it will adopt the late binding technology based on the type of the passed object.
To determine which function to call (parent class or subclass ). The premise is to pass the pointer of the subclass: If the subclass has a child class, the Child class does not call the parent class.
There is also a pure virtual function: the parent class only defines the operation and does not implement it. The inherited class must implement it.
# Include <iostream>
Using namespace STD;
Class animal
{
Public:
Static const int cc = 1;
/* Virtual */void breathe ()
{
Cout <"Animal breath" <Endl;
}
// Virtual void breathe () = 0;
};
Class fish: Public animal
{
Public:
Fish (): A (22)
{
}
Void breathe ()
{
Cout <animal: CC <Endl;
Cout <"fish breathe" <Endl;
}
PRIVATE:
Const int;
};
Void fun (animal * Pan)
{
Pan-> breathe ();
}
Int main ()
{
Fish fi;
Animal * pA;
Pa = & fi;
Fun (PA );
System ("pause ");
Return 0;
}