Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Creating C++ virtual functions that can be overridden in Python requires some work - see <a href="http://www.boost.org/doc/libs/1_42_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.class_virtual_functions" rel="nofollow noreferrer">here</a>. You will need to create a wrapper function in a derived class that calls the Python method. Here is how it can work:</p> <pre><code>struct ConnectionBaseWrap : ConnectionBase, wrapper&lt;ConnectionBase&gt; { void OnEvent(const Overload_a &amp;obj) { if (override f = get_override("OnEventOverloadA")) f(obj); } void OnEvent(const Overload_b &amp;obj) { if (override f = get_override("OnEventOverloadB")) f(obj); } }; BOOST_PYTHON_MODULE(yourmodule) { class_&lt;ConnectionBaseWrap, boost::noncopyable&gt;("ConnectionBase") //Your additional definitions here. ; } </code></pre> <p>Some notes:</p> <ul> <li><p>Since you won't be calling the base class's OnEvent function from Python, you don't need to define it with <code>.def</code>. If you did want to define it, you'd need to give the two overloaded versions different names, like <a href="http://www.boost.org/doc/libs/1_42_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.overloading" rel="nofollow noreferrer">here.</a></p></li> <li><p>The two overloads will call different Python methods: <code>OnEventOverloadA</code> and <code>OnEventOverloadB</code>. Another option is to have them both call the same method <code>OnEvent</code>, and then one Python method will override both overloads.</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload