2

In the following code:

struct X{ 
    void stream(int){} 
};
struct Y : public X{
    void stream(int, int){}
};

int main()
{
    Y y;
    y.stream(2);
}

Why X::stream(int) is not inherited?

Or it is hided with Y::stream(int, int). If so, why it hidden, not overridden?

tower120
  • 5,007
  • 6
  • 40
  • 88
  • A derived class member function hides base class member functions of the same name regardless of signature. There must be a dup somewhere... – T.C. Jun 22 '14 at 18:13
  • Here: http://stackoverflow.com/questions/5368862/why-do-multiple-inherited-functions-with-same-name-but-different-signatures-not?rq=1 – chris Jun 22 '14 at 18:13
  • @chris But there is no ambiguous calls. – tower120 Jun 22 '14 at 18:14

1 Answers1

3

Names in derived classes do indeed hide identical names in base classes. This is deliberate. If the base class changes, you don't suddenly and silently want to see a different overload set in your derived class.

To unhide base names explicitly, add using X::stream; into your derived class.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084