class C {
public:
DWORD counter;
void foo2() {this->foo();};
private:
virtual void foo() {counter=1;};
};
class B:public C {
public:
void foo(){counter=2;};
private:
};
B b;
b.counter = 0;
b.foo2();
I have run this code and got counter equal to 2.
I want to be sure what is happening here.
I can overload a method in the parent class that was private?
More then that, the method in the son class became public?
Maybe I am incorrect and something else happens?
private virtual?
Consider the following code:
You made the virtual function public by placing the definition/decleration there. It also doesn't matter if an overloaded function is private. Remember, inside the class nothing is really hidden. Even if you inherited privately, it wouldn't matter (except counter would be private, therefor the compiler would get mad).
I thought that the son class inherits only the public and protected of its parent? So class B cannot use private methods or private members of class C.
However, it can overload a private virtual method in C? That is odd.
However, it can overload a private virtual method in C? That is odd.
Quote:Original post by The C modest god
I thought that the son class inherits only the public and protected of its parent?
No, it inherits everything; it just doesn't have access to private members.
Quote:Original post by SneftelQuote:Original post by The C modest god
I thought that the son class inherits only the public and protected of its parent?
No, it inherits everything; it just doesn't have access to private members.
Ok, thanks.
Your post kind of didn't make sense. C::Foo remains private. You couldn't call it from B if you wanted to. But you *can* override it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement