[C++-sig] virtual functions with default implementation
Alex Mohr
amohr at pixar.com
Mon Aug 17 20:54:34 CEST 2015
On 8/17/2015 11:39 AM, Stefan Seefeld wrote:
> For the case with default implementation, the tutorial gives this wrapper:
>
> struct BaseWrap : Base, bpl::wrapper<Base>
> {
> virtual std::string func() const
> {
> if (bpl::override f = this->get_override("func"))
> return f();
> else
> return Base::func();
> }
> std::string default_func() const { return this->Base::func();}
> };
>
> and it seems to me much more natural to implement the "default" case
> directly in the "else" branch above, rather than add it to the "def()" call.
I think this might be so that python can invoke the superclass (C++)
implementation directly in its override, but I'm not 100% sure.
Alex
More information about the Cplusplus-sig
mailing list