Inherited
Derive from one class to another class so that all features of the former are automatically available in the latter. He can declare some types, which can share some or all of the previously declared types. It can also share some attributes from more than one base class. C + + is support for multiple inheritance.
After the inheritance modifier for the class:
With private inheritance, all methods of the parent class become private in subclasses;
With protected inheritance, the protected and public methods of the parent class change to Protected,private method in the subclass;
Using public inheritance, the method attribute in the parent class does not change;
|
Public |
Protected |
Private |
| Public inheritance |
Public |
Protected |
--- |
| Protected inheritance |
Protected |
Protected |
--- |
| Private inheritance |
Private |
Private |
--- |
Class Fruit{public:peel (); slice (); juice ();p rivate:int weight;int height;}; Class Apple:public fruit{public:void make_candy_apple (float weight); void Bob_fro (int tub_id, int num_of_attempts);}
Do not confuse one class inside another with inheritance. The nesting of classes does not have special permissions, and there is no special relationship with nested classes. Nesting is often used to implement container classes (classes that implement some data structures, such as linked lists, queues, and so on). C + + adds templates (template) that are used to implement container classes. Inheritance indicates that an object is a special type of a more generic parent object.
—————————————————————————————————————————————————————————————————————————————
Multiple inheritance
Multiple inheritance allows you to combine two classes into one so that the result class object behaves like any of these two classes of objects. It turns the tree-like system into a lattice.
—————————————————————————————————————————————————————————————————————————————
Polymorphic-run-time binding
Polymorphic, supporting related objects have different member functions (but the same prototype), allowing the object to run with the appropriate member functions for binding. C + + supports this mechanism through overrides --all polymorphic member functions have the same name, which is best judged by the runtime system. This mechanism is used when inheriting: Sometimes you cannot tell at compile time whether the object you have is a base class object or a derived class object. This process of judging and invoking the correct function is called late binding. The member function plus the virtual keyword tells the compiler that the member function is polymorphic.
In an ordinary compile-time overload , the function prototype must be significantly different, so that the compiler can see the type of erasure to determine the need to call that function, but in the virtual function, the function of the prototype must be the same, there is a runtime system to parse the call which function, this process is called overwrite . Overloading occurs between different functions in the same class, and overrides occur in multiple classes of inheritance.
Polymorphism refers to the ability of a function or operator to have only one name, but it can be used for several different derived types. Each object implements a variant of the operation that behaves best for itself. It starts with overwriting a name and reusing the same name so that it can behave differently.
From c to C + + (bottom)