[C++-sig] How do I wrap virtual methods
David Abrahams
dave at boost-consulting.com
Fri Aug 5 17:57:47 CEST 2005
Eric Jardim <ericjardim at gmail.com> writes:
> I saw on the tutorial that you should use a construct like:
>
> struct BaseWrap : Base, wrapper<Base>
> {
> int f()
> {
> if (override f = this->get_override("f"))
> return f(); // note*
> return Base::f();
> }
>
> int default_f() { return this->Base::f(); }
Does the tutorial really recommend that default_f? I can't imagine
why. That's just wrong; you don't need it and it's a bad idea to use
it. [Joel, can you please fix this ASAP, and the use of default_f
further down?]
> };
>
> // *note: on MSVC use
> // return call<char const*>(f.ptr());
>
> I think that this will solve the problem, because it tests if there is a
> overriden method. I am still confused if wrapper<...> will create the
> apropriate contructors.
wrappeer<...> doesn't create any constructors by itself.
> So what do "wrapper<..>" really do?
Exactly what's described in
http://www.boost.org/libs/python/doc/v2/wrapper.html#wrapper-spec
> Another thing that I noticed is that I have to reimplement virtual methods
> on every derived class. This is an accumulative task. Am I right?
I don't know what you mean.
> So, what is the right and safe way to wrap virtual methods?
Everything the tutorial says, aside from the definition and use of
default_f, seems to be right.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list