Introduction
About method members, not attribute members.
Term
- Overloading: two or more methods in one class have the same method name but different parameters.
- Overriding: two methods with the same method name and parameters (i.e., method signature). One of the methods is in the parent class and the other is in the child class.
Declaration and defintion
C++ compiler thinks the following are different declarations
void func(int x){} void func(float x){} void func(double x){} void func(int & x){} class F{}; class G: public F{}; void func(F x){} void func(G x){}
C++ compiler does not allow the following overloading
void func(int x){ } int func(int x){ } // functions that differ only in their return type cannot be overloaded
Calling
C++ compiler interrupts number value with following equal preference. Therefore it can cause calling ambiguous.
- double -> double or float
- float -> double or float
- int -> int or double or float
- Moreover, compiler cannot distinguish call by reference or call by value.
C++ compiler prefers to use most close class type to interrupt class value.
What can be distinguished: #parameter, order of parameter (but double -> float, float -> double, int -> float, int -> double)
What can not be distinguished: reference or not. e.g. func(int x); and func(int &x);