1. Overloading:
Overloading is a series of functions in which a class, like a function name, has a different parameter type or number of arguments
It is important to note that it is independent of the return type.
class test{ public : void show (); void Show (int a); void Show (double a); void Show (int a,int b); void Show (int a,double b);};
2. Rewrite
Another word we're more familiar with is "overlay."
In the case of inheritance, if the subclass does not redefine the virtual method of the parent class , the child class object is still using the method of the parent class when calling the method;
Otherwise, the child class overrides the virtual method of the parent class, which is called with a redefined method.
classtest{ Public: Virtual voidShow () {Std::cout<<"test::show ()"<<Std::endl; }};classSubtest: Publictest{ Public: Virtual voidShow () {Std::cout<<"subtest::show ()"<<Std::endl; }};intMain () {Test*p =Newsubtest; P-Show (); return 0;}
Output Result:
Subtest::show ()
3. Redefining
Another word we're more familiar with is "hiding."
subclasses redefine a non-virtual function in the parent class that has the same name , and then the object calls the non-virtual method, using the method defined by the object itself.
classtest{ Public: voidShow () {Std::cout<<"test::show ()"<<Std::endl; }};classSubtest: Publictest{ Public: Virtual voidShow () {Std::cout<<"subtest::show ()"<<Std::endl; }};intMain () {Test*p =Newsubtest; P-Show (); return 0;}
Output Result:
Test::show ()
With respect to rewriting and redefinition, it is easy to understand the principle of a virtual function table,
On virtual function table, refer to C + + virtual function table and virtual destructor function
C + + overloading, overriding, redefining