home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: Overloading Parent Declaration: Bug or Feature?
- Message-ID: <1992Aug21.153319.27093@taumet.com>
- Organization: TauMetric Corporation
- References: <1992Aug20.141830.3079@rhrk.uni-kl.de>
- Date: Fri, 21 Aug 1992 15:33:19 GMT
- Lines: 31
-
- kring@efes.physik.uni-kl.de (Jochen Voss) writes:
-
- |I tried to compile the following program with GNU C++ version 2.1
-
- | class B {
- | public:
- | void f(int x) { cout << "B::f(" << x << ")\n"; }
- | };
- | class D : public B {
- | public:
- | void f(char *str) { cout << "D::f(" << str << ")\n"; }
- | };
- | main()
- | {
- | D d;
- | d.f(1); // (*) should be an error ?
- | }
-
- |It compiles without warnings (even with the -Wall flag set) and outputs
- | B::f(1)
-
- The compiler is wrong. An identifier in a derived class hides all
- instances of that identifier in all its base classes. In this
- example, only the version of f() taking a char* is visible, so the
- call is illegal. You could write "d.B::f(1)", however.
-
- I assume this bug has been fixed in a more recent version of g++.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
- Vice Chair, ANSI C++ Committee, X3J16
-