If I have in C++:
class A {
private: virtual int myfunction(void) {return 1;}
}
class B: public A {
private: virtual int myfunction(void) {return 2;}
}
Then if I remove virtual
from the myfunction
definition in class B
, does that mean that if I had a class C
based on class B
, that I couldn't override the myfunction
since it would be statically compiled?
Also, I'm confused as to what happens when you switch around public, and private here. If I change the definition of myfunction
in class B
to be public (and the one in class A
remains private), is this some sort of grave error that I shouldn't do? I think that virtual functions need to keep the same type so that's illegal, but please let know if that's wrong.
Thanks!