1

I was pretty long in some Java project, and calling the parent's virtual functions went like this:

int func(..) {
    super.func(..);
}

But now as I return to C++, this is the way I thought It'd work (for Constructors this works) like this, but I was mistaken. I even forgot how this is called. ((Component)this)->func(); doesnt work either, so I'm lost.

int Label::func() : Component::func() {
}

How is it done correctly?

Thanks in advance!

4

2 回答 2

6

您应该从超类显式调用函数:

int Label::func() 
{
    return Component::func();
}
于 2012-10-06T09:49:44.230 回答
4

我以前见过这个(尽管在 C++ 中人们经常说 Base 而不是 Super):

class Label : Component
{
   typedef Component Super;

   int func()
   {
     Super::func();
   }
};
于 2012-10-06T09:59:59.953 回答