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
}
//...
};
I know that get() in Derived class will hide get() and get(int x) methods inside Base class. so My question is:
1) is this consedred overloading or overriding ?
2) does making get() const in the derived class will change something about (hiding or not hiding Base class methods).
Quote from a c++ book:
“It is a common mistake to hide a base class method when you intend to override it, by
forgetting to include the keyword const. const is part of the signature, and leaving it off
changes the signature, and thus hides the method rather than overrides it. “
It is neither overloading nor overriding. Rather, it is hiding.
If the other function were also visible, it would be overloading, which you can achieve with
using:Even if you declared
int get() constin the derived class, it would merely be hiding the base function, since the base function is notvirtual.