H
Hongzheng Wang
Hi,
I have a problem about the overriding of private methods of base
class.
That is, if a method f() of base class is private, can the derived
class overriding f() be overriding?
For example,
class base {
private:
virtual void f() {
//some codes
}
public:
void ff() {
f();
//invoke the f()
}
};
class derived : public base {
public:
virtual void f() {
//some other codes
}
};
int main()
{
base * pobj = new derived;
pobj->f();
//which method will be invoked here?
//the base's f() or derived's one?
return 0;
}
I have a problem about the overriding of private methods of base
class.
That is, if a method f() of base class is private, can the derived
class overriding f() be overriding?
For example,
class base {
private:
virtual void f() {
//some codes
}
public:
void ff() {
f();
//invoke the f()
}
};
class derived : public base {
public:
virtual void f() {
//some other codes
}
};
int main()
{
base * pobj = new derived;
pobj->f();
//which method will be invoked here?
//the base's f() or derived's one?
return 0;
}