[C++-sig] abstract class and virtual function

Roman Yakovenko roman.yakovenko at gmail.com
Mon Apr 16 07:25:07 CEST 2007


On 4/16/07, Quant Mind <quant.mind at gmail.com> wrote:
>
> I'm running into some problem in exposing an abstract class with some
> virtual functions with default implementations (no problem with pure
> virtuals).
> The problem seems quite trivial but I cannot get to the bottom of it.
>
> struct rateWrap : public irate, public boost::python::wrapper<irate>
> {
> bool    isScalar() const;
> double value() const;
> //
> bool    default_isScalar()    { return this->irate::isScalar(); }
> double default_value()   { return this->irate::value(); }
> };
> //
> inline bool rateWrap::isScalar() const
>     {
>       if(boost::python::override overfun = this->get_override("isScalar"))
>
> #ifdef  _MSC_VER
>         return boost::python::call<char const*>(overfun.ptr());
> #else
>         return overfun();
> #endif  //  _MSC_VER
>       return irate::isScalar();
>     }
> //
> inline double rateWrap::value() const
>     {
>       if(boost::python::override overfun = this->get_override("value"))
> #ifdef  _MSC_VER
>         return boost::python::call<char const*>(overfun.ptr());
> #else
>         return overfun();
> #endif  //  _MSC_VER
>       return irate::realvalue();
>     }
>
> While the first function, returning bool, works fine :) the second one,
> returning double, does not work!!! :(
> I'm compiling with Microsoft Visual Studio 2005 which returns the
> following error
>
> 'return' cannot convert from 'const char *' to 'double'
>
> I don't know what is the problem, any advise?
>

In both cases you return  "char const*" , probably it should be :

        return boost::python::call<bool>(overfun.ptr());
and
        return boost::python::call<double>(overfun.ptr());



-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070416/aca0e35d/attachment.htm>


More information about the Cplusplus-sig mailing list