virtual functions changing from protected to private - question

MatthiasM dm at matthiasm.com
Tue Sep 5 12:43:13 PDT 2006


So, umm, after debugging my app for quite a while (OSX gdc), I saw that 
B.draw is not called. Is that intentional?

class Window {
protected:
   void draw() {
     writefln("Window");
   }
}

class MenuWindow : Window {
private:
   void draw() {
     writefln("MenuWindow");
   }
}

Window w = new MenuWindow();
w.draw();


prints "Window". I would have expected "MenuWindow", thinking that all 
functions are automatically virtual. I understand that private unctions 
are not virtual on a base class, since they can't be overridden anyways. 
But is that true for a derived class too?

Matthias



More information about the Digitalmars-d-learn mailing list