-1
近日,筆者瞭解到,重新定義,在派生類中,非虛基類成員函數會將這些函數隱藏在基類中。例如
class base
{
public:
virtual ~base() {}
void process(int x);
void process(double d);
virtual base& id();
};
class derived1 : public base
{
public:
void process(); // hides base process functions
derived1& id();
//using base::process; // this will unhide both base process members
};
int main(){
derived1 d1;
d1.id().process();
//d1.id().process(3);
//d1.id().process(3.5);
// won't compile because process() hides base::process(int)
// unless we uncomment using base::process; statement in class declaration.
}
這個例子顯示我們可以通過「using base :: xxx」語句使基函數取消隱藏。但我有兩個問題:
- 爲什麼C++隱藏重載基函數?
- 如何理解語句「using base :: process;」
[可能重複](http://stackoverflow.com/questions/4837399/c-rationale-behind-hiding-rule) – peoro 2011-03-04 04:15:29