Article View: comp.std.c++
Article #3152Re: base class operator hiding
From: Russell Johnston
Date: Fri, 26 Jan 1996 00:05
Date: Fri, 26 Jan 1996 00:05
44 lines
2307 bytes
2307 bytes
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; }
From the ARM (Section 13.1), or section 13.2.1 in Draft Standard:
"A function member of a derived class is *not* in the same scope
as a function member of the same name in a base class."
The next page [ARM] gives a justification for this decision, the
jist of which is that in a chain of derived classes, a "best match"
may be found deep in the base class which will surprise programmers
using the derived class.
Cheers,
Russell Johnston
<rjohnsto@edge.net>
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<3107ADA2.2D5F2D3@edge.net>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<01BAE8B0.C408A920@dino.int.com> <4e1in5$5en@news02.comp.pge.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: Russell Johnston <rjohnsto@edge.net> Newsgroups: comp.std.c++ Subject: Re: base class operator hiding Date: 26 Jan 1996 00:05:33 GMT Organization: mainly carbon-based Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <3107ADA2.2D5F2D3@edge.net> References: <01BAE8B0.C408A920@dino.int.com> <4e1in5$5en@news02.comp.pge.com> NNTP-Posting-Host: taumet.eng.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Nntp-Posting-Host: ip159.nash.edge.net X-Mailer: Mozilla 2.0b6a (X11; I; Linux 1.3.59 i486) To: Phillip Knight <psk3@pge.com> X-Lines: 40 Content-Length: 1325 Originator: clamage@taumet