I have some virtual methods with default implementations that I am defining according the guidelines on the documentation and I ran into some unexpected behavior.<br>If I define a virtual method in boost python like so<br>
<br>void receivedMsg( const sl::Message& msg )<br>{<br> if( bp::override func_receivedMsg = this->get_override( "receivedMsg" ) )<br> func_receivedMsg( boost::cref( msg ) );<br>}<br><br>
it works fine, my receivedMsg function gets called in python no problem. Note that I am not calling the default implementation because the default implementation does not do anything, I do not want to make them pure virtual because the idea is that the user only has to define the methods he wants notifications on.<br>
<br>My trouble comes when I do<br><br>void receiverDeleted( const std::string& type, const std::string& name )<br>{<br> if( bp::override func_receiverDeleted = this->get_override( "receiverDeleted" ) )<br>
func_receiverDeleted( boost::cref( type ), boost::cref( name ) );<br>}<br><br>I get a error_already_set exception because the mechanics under the hood cannot pythonize the boost::cref( type ). In my first example, Message is defined in python so I guess cref works like that, but the default converter for std::string must not like the boost::cref wrapper. I do not get the exception and it seems to work fine if I remove the crefs.<br>
<br>I added the cref's a while ago because it seemed like the right thing to do. I do not want boost::python creating copies of my objects under the hood, maybe it does anyway, I do not know.<br><br>Do the crefs do anything? Should I even have them? Is this a bug or just me being stupid? :p<br>
<br>Thanks<br>