Article View: comp.std.c++
Article #3075base class operator hiding
From: Phillip Knight
Date: Tue, 23 Jan 1996 03:34
Date: Tue, 23 Jan 1996 03:34
44 lines
1991 bytes
1991 bytes
This may or may not be appropriate for this group, but here goes:
Given this code snippet:
#include <strstream.h>
class foo {};
class ologstream : public ostream {
public:
ologstream() {}
virtual ~ologstream() {};
ologstream& operator<< (foo &bar)
{ return *this; } // do nothing
};
int main(int, char **)
{
ologstream out;
out << "Test one.";
return 1;
}
The program does not compile, giving an error where the char * is acted
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 or in the implementation, or is it just me? I have attempted this
code fragment on several compilers with the same results, which makes me
wonder...
This fragment, btw, is for illustration, not as an example of good coding
or design.
Thanks for your time and consideration,
Phil Knight
psk3@pge.com
---
[ 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:
<4e1in5$5en@news02.comp.pge.com>Path:
arc1-ca.pugleaf.net!cs.mu.OZ.AU!bounce-backReferences:
<01BAE8B0.C408A920@dino.int.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!cs.mu.OZ.AU!bounce-back From: psk3@pge.com (Phillip Knight) Subject: base class operator hiding Message-ID: <4e1in5$5en@news02.comp.pge.com> Originator: fjh@munta.cs.mu.OZ.AU Sender: news@cs.mu.OZ.AU (CS-Usenet) Organization: Pacific Gas and Electric X-Newsreader: WinVN 0.99.6 References: <01BAE8B0.C408A920@dino.int.com> X-Original-Date: 23 Jan 1996 02: 55:33 GMT Date: Tue, 23 Jan 1996 03:34:26 GMT Approved: fjh@cs.mu.oz.au X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMQRXgeEDnX0m9pzZAQEtmQF/Tp7W/6Q8RCLWJyQYxYNsF6eyJnYoEWc4 r9tBAggGClAdTwHj++O3SPvW9M38RwVJ =0kBG