[C++-sig] virtual method issue ?

Roman Yakovenko roman.yakovenko at gmail.com
Fri Mar 16 11:24:41 CET 2007


On 3/16/07, Adrien Saladin <adrien-ml at wizzi.net> wrote:
> _Grad[0] =0
> python: minim.cpp:49: void Minimizer::minimize(): Assertion `_Grad[0]>=5.0'
> failed.

struct BaseWrap: Base, wrapper<Base>
{
   double Function(const Vdouble& v, Vdouble& Grad)
   {
       return this->get_override("Function")(v,Grad);
   }

};

This code should be changed to

return this->get_override("Function")(boost::ref(v), boost::ref(Grad));

By default boost::python::object holds a copy of the instance.

The code generator I created, Py++ is aware to this and generates right code.
It has GUI, so you can create simple test case and see what code it
will generate.

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list