home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12731 < prev    next >
Encoding:
Text File  |  1992-08-21  |  1.2 KB  |  42 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: Overloading Parent Declaration: Bug or Feature?
  5. Message-ID: <1992Aug21.153319.27093@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1992Aug20.141830.3079@rhrk.uni-kl.de>
  8. Date: Fri, 21 Aug 1992 15:33:19 GMT
  9. Lines: 31
  10.  
  11. kring@efes.physik.uni-kl.de (Jochen Voss) writes:
  12.  
  13. |I tried to compile the following program with GNU C++ version 2.1
  14.  
  15. |    class B {
  16. |    public:
  17. |        void f(int x)    { cout << "B::f(" << x << ")\n"; }
  18. |    };
  19. |    class D : public B {
  20. |    public:
  21. |        void f(char *str)    { cout << "D::f(" << str << ")\n"; }
  22. |    };
  23. |    main()
  24. |    {
  25. |        D d;
  26. |        d.f(1);        // (*) should be an error ?
  27. |    }
  28.  
  29. |It compiles without warnings (even with the -Wall flag set) and outputs
  30. |    B::f(1)
  31.  
  32. The compiler is wrong.  An identifier in a derived class hides all
  33. instances of that identifier in all its base classes.  In this
  34. example, only the version of f() taking a char* is visible, so the
  35. call is illegal.  You could write "d.B::f(1)", however.
  36.  
  37. I assume this bug has been fixed in a more recent version of g++.
  38. -- 
  39.  
  40. Steve Clamage, TauMetric Corp, steve@taumet.com
  41. Vice Chair, ANSI C++ Committee, X3J16
  42.