[C++-sig] Re: How to expose virtual function with defaultarguments in boost.python ?

David Abrahams dave at boost-consulting.com
Wed Dec 8 04:50:14 CET 2004


Baptiste Lepilleur wrote:
>>
>> Why not just
>>
>>                return call< const Ogre::String& >( f.ptr());
> 
>>
>> ??
>>
>> >         return Ogre::BillboardSet::getMaterialName();
>> >     }
>> > ---
>> >
>> > Do you have any idea on how to "remove" this warning?
>>
>> The warning is a compiler bug; I reported it late in the vc7.1 release
>> cycle and they were not inclined to fix it.
> 
> 
> I changed the generator to generate the "vc6/7 work-around" code. I wanted
> to see if there was a difference, and there is ! 

What sort of a difference?

> There should definitely be
> a note about this warning in either the tutorial or the reference
> documentation.

Where, precisely, do you think the note could go that would be helpful?
 The warning shows up in all kinds of places, and not only with
Boost.Python.  If it will be helpful, I'm all for adding a note, but in
general I'm disinclined to devote much attention to suppressing buggy
warnings.  I don't want the documentation to become a pile of notes
about quirky compiler bugs.

> It worries me that such a serious warning is bugged. It's one of a few that
> I really look out for. By the way, how do you manage to return a reference
> on something that is temporary (return value of the python function call) ?
> I'm curious...

I am not returning a reference to a temporary; that's why I say the
warning is a compiler bug.  The warning is just incorrect.

> I just have one last issue remaining. It concerns the binding of *protected*
> virtual function with default parameters.
> 
> Take the following code excerpt:
> 
> ---
> struct Ogre_SceneManager_Wrapper: Ogre::SceneManager
>                                 , wrapper< Ogre::SceneManager > {
> //...
>     void renderSingleObject(
>                Ogre::Renderable* p0,
>                Ogre::Pass* p1,
>                bool p2,
>                const Ogre::LightList* p3) {
>         if (override f = this->get_override("renderSingleObject"))
>             call< void >( f.ptr(), p0, p1, p2, p3);
>         Ogre::SceneManager::renderSingleObject(p0, p1, p2, p3);
>     }
> 
>     static void default_renderSingleObject_3(
>                   Ogre::SceneManager &self,
>                   Ogre::Renderable* p0,
>                   Ogre::Pass* p1,
>                   bool p2) {
>         self.renderSingleObject(p0, p1, p2);        // <<<= problem there
>     }
> 
>     void default_renderSingleObject(
>                 Ogre::Renderable* p0,
>                 Ogre::Pass* p1,
>                 bool p2,
>                 const Ogre::LightList* p3) {
>         Ogre::SceneManager::renderSingleObject(p0, p1, p2, p3);
>     }
> };
> ---
> 
> The virtual member function renderSingleObject is defined has protected in
> the wrapped class Ogre::SceneManager. This means that we can't call the base
> class member function using "self.". I'm not aware of any tricks to work
> around this, do you know any ?


Nope.  As with private non-pure virtual functions, this may be one of
those corner cases where you have to forcibly violate the encapsulation
of the code you're wrapping (usually by adding friend declarations).

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com




More information about the Cplusplus-sig mailing list