我是总是区分不开重载和覆盖的概念,总是弄混淆,下面我就用例子解释下:
Class A
{
public:
hello(){cout<<”无参数的函数“;}
hello(int i){cout<<"一个参数的函数";}//这里就是hello函数的重载,函数名相同,函数参数类型及个数不同
};
Class B: public A
{
public:
hello(){cout<<"类B的函数";}//这里就是hello函数的覆盖,子类将父类中的函数覆盖
hello()const{cout<<"带const函数"}//这里的带const的hello函数和不带const的hello函数不同,只能被const对象调用,也可以说是hello函数的重载
};