class Base{
//...
public:
int get()const{ // const
// Do something.
}
int get(int x){
// Do Someting.
}
//...
};
class Derived:public Base{
//....
public:
int get(){ // not const (not the same signature as the one is the base class)
//Dosomething
}
//...
};
我知道,获得()的派生类将隐藏get()和获取(INT X)的基类中的方法。所以我的问题是:
1)这是conconred重载或覆盖?
2)在派生类中get()const会改变一些内容(隐藏或不隐藏基类方法)。
“这是一个常见的错误隐藏基类的方法,当你打算重写它,通过 忘记包括关键字const常量是签名的一部分,和:从C++的书
报价离开它关闭 改变了签名,从而隐藏方法,而不是覆盖它。“
重载:http://en.wikipedia.org/wiki/Function_overloading,覆盖:http://en.wikipedia.org/wiki/Method_overriding – alfa 2012-03-25 18:54:07
第二个得到基地错过了返回类型 – 2012-03-25 18:56:56