Topic: base class operator hiding


Author: Russell Johnston <rjohnsto@edge.net>
Date: 1996/01/26
Raw View
Phillip Knight wrote:

>         class ologstream : public ostream {
>            public:
 [ ... ]
>            ologstream& operator<< (foo &bar)
>                    { return *this; }  // do nothing
>         };

[ main() then attempts to use ologstream::operator<< on char*]

> on by ostream/ologstream operators.  The presence of an operator<<
> (overloaded or otherwise) in the dervided class consequently hides the base
> class operators which are public.  My question is; is this a bug in the
> language [...] ?


I believe this is the expected behavior for the language.
You can call the base class version with:

  out.ostream::operator<< ("Test one.");

Or (perhaps better depending on how "natural" you want the
char * version to feel) give ologstream a member:

  ologstream& operator<< (char *str)
      { ostream::operator(str); return *this; }