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