Topic: comp.lang.c++


Author: hitz@csi.UOttawa.CA (Martin Hitz)
Date: Tue, 4 Dec 90 12:43:56 EST
Raw View
I find it awkward that it is possible (at least with g++ and Zortech 2.0)
to implicitely call a private member function via the virtual mechanism as
in the following example:

 class B {
  public:
  virtual void f() { cout << "B\n"; }
 };

 class D: B {
  void f() { cout << "D\n"; }
 };

 main()
 {
  D  d;
  B& b = d;
  b.f();  // prints "D"
 }

My opinion is that this shouldn't be possible, i.e. the compiler
should complain about the private version of f() in the derived
class D.

Any comments?

Best regards, Martin Hitz

hitz@csi.UOttawa.CA