简体   繁体   中英

how do I call a base class method from the derived class, if the derived class has a method with the same name?

this is what I want to be able to do: (pseudo code)

class DerivedClass : public BaseClass
{
    public Draw()
    {
        BaseClass.Draw()
    }
}

class BaseClass
{
    protected Draw();
}

Both draws have the same name and the same signature. The reason for wanting to do this is that sometimes I want my derived classes to have a draw function that simply calls the Base Classes draw, but at other times I want the derived class to choose when to call the base draw function or not. This meant that I can keep the class that I instantiate the derived classes in much cleaner, and can just call draw on all of them at all times. The derived classes themselves handle the nitty-gritty.

What exactly is the syntax for the BaseClass.Draw part? I thought you could actually just write that as it is, but the compiler is complaining, and it's not like I can just call Draw because the signatures are the same.

语法是BaseClass::Draw()

The syntax is

DeriveClass::Draw()
{
   BaseClass::Draw();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM