4 c++ polymorphism inheritance overloading
为什么这不起作用,什么是一个好的选择?
class Grandparent
{
void DoSomething( int number );
};
class Parent : Grandparent
{
};
class Child : Parent
{
void DoSomething()
{
Grandparent::DoSomething( 10 ); // Does not work.
Parent::DoSomething( 10 ); // Does not work.
}
};
Run Code Online (Sandbox Code Playgroud)
Jos*_*erg 12
class Grandparent
{
protected:
void DoSomething( int number );
};
class Parent : protected Grandparent
{
};
class Child : Parent
{
void DoSomething()
{
Grandparent::DoSomething( 10 ); //Now it works
Parent::DoSomething( 10 ); // Now it works.
}
};
Run Code Online (Sandbox Code Playgroud)
至少它需要看起来像这样.在使用类时,默认情况下是私有的,这包括子类.
有一个完整的例子可以编译和运行.