So I have 2 classes, foo and bar. bar is a subclass of foo. Both bar and foo have virtual functions intended to be overridden form python.<br><br>struct foo<br>{<br> foo(){} ;<br> foo(int init_x, int init_y){x=init_x;y=init_y;};<br>
int x;<br> int y;<br><br> virtual void FooCallback(){std::cout << "default foo called" << std::endl;};<br>};<br><br>struct bar : foo<br>{<br> bar(){} ;<br> bar(int init_x, int init_y, int init_z):foo(init_x,init_y){z = init_z;};<br>
<br> virtual void BarCallback(){std::cout << "default bar called" << std::endl;};<br><br> int z;<br>};<br><br>struct foo_wrapper : foo , wrapper<foo><br>{<br> foo_wrapper();<br> foo_wrapper(const foo& f);<br>
foo_wrapper(int init_x, int init_y);<br><br> virtual void FooCallback();<br>};<br><br>void foo_wrapper::FooCallback()<br>{<br> std::cout << "atemptting foo callback" << std::endl; <br> if (override func = this->get_override("FooCallback"))<br>
{<br> func();<br> return;<br> }<br> else<br> std::cout << "foo callback function not found" << std::endl;<br>}<br><br>foo_wrapper::foo_wrapper(const foo& exch): foo(exch), wrapper<foo>(){}<br>
foo_wrapper::foo_wrapper(): foo(), wrapper<foo>(){}<br>foo_wrapper::foo_wrapper(int init_x, int init_y) : foo(init_x,init_y), wrapper<foo>(){}<br><br>struct bar_wrapper: bar, wrapper<bar><br>{<br> bar_wrapper();<br>
bar_wrapper(const bar& b);<br> bar_wrapper(int init_x, int init_y, int init_z);<br><br> virtual void BarCallback();<br>};<br><br>bar_wrapper::bar_wrapper(const bar& exch): bar(exch), wrapper<bar>(){}<br>
bar_wrapper::bar_wrapper(): bar(), wrapper<bar>(){}<br>bar_wrapper::bar_wrapper(int init_x, int init_y, int init_z) : bar(init_x, init_y, init_z), wrapper<bar>(){}<br><br>void bar_wrapper::BarCallback()<br>{<br>
std::cout << "atemptting bar callback" << std::endl; <br> if (override func = this->get_override("BarCallback"))<br> {<br> func();<br> return;<br> }<br> else<br>
std::cout << "bar callback function not found" << std::endl;<br>}<br><br>void backcaller(bar& b)<br>{<br> b.BarCallback();<br> b.FooCallback();<br>}<br><br>BOOST_PYTHON_MODULE(busybox)<br>
{<br> class_<foo_wrapper>("foo")<br> .def(init<>())<br> .def(init<int, int>())<br> .ENABLE_COPY(foo)<br> .def_readwrite("x", &foo::x )<br> .def_readonly ("y", &foo::y )<br>
;<br><br> class_<bar_wrapper, bases<foo> >("bar")<br> .def(init<>())<br> .def(init<int,int,int>())<br> .ENABLE_COPY(bar)<br> .def_readwrite("z", &bar::z)<br>
;<br><br> def("backcaller", &backcaller);<br>}<br><br>in python:<br>>>> import busybox<br>>>> class myBar(busybox.bar):<br>... def FooCallback(self):<br>... print "this is a foo callback"<br>
... def BarCallback(self):<br>... print "this is a bar callback"<br>...<br>>>> b = myBar()<br>>>> busybox.backcaller(b)<br>atemptting bar callback<br>this is a bar callback<br>default foo called<br>
>>><br><br>So the question is: why is the default FooCallback in foo getting called rather then the FooCallback in myBar? <br>What can I do about it?<br><br>