[C++-sig] Interfacing pure abstract classes with Boost.Python

David Abrahams dave at boost-consulting.com
Thu Jan 23 20:39:47 CET 2003


"Pere Mato Vila" <Pere.Mato at cern.ch> writes:

> Hi all,
>
>   I have problems interfacing pure abstract classes, which I do not
> intend to extent from the Python side, with version 2 of Boost.Python.
>
> The class IHistogram is defined as
>
> class IHistogram   {
> public: 
>   virtual int dimension (  ) const = 0;
>   ...
> };
>
> I expose it as
>
>   python::class_<IHistogram, boost::noncopyable > ("IHistogram",
> python::no_init )
>     .def("dim",   &IHistogram::dimension )
>   ...
>
> And I provide the method iHistogramSvc::book1D(...) which returns an
> IHistogram* and is exposed as
>
>   python::class_<GaudiPython::iHistogramSvc>
>      ( "IHistogramSvc", python::init<IHistogramSvc*>() )
>     .def("book",       &GaudiPython::iHistogramSvc::book1D )
>
> So far so good. I am able to compile and produce the Python extension
> module. But, when I run the Python code I get:
>
>>>> gaudi.IHistogram1D
> <class 'gaudimodule.IHistogram1D'>
>>>> h1 = his.book('1', 'histogram title', 10, 0, 10)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: No to_python (by-value) converter found for C++ type: class
> IHistogram1D
>
>
>   What I am doing wrong? 

To begin with, you're not showing enough of your code, or you're not
showing it accurately.  Where is "IHistogram1D" coming from, for
example?  That's not mentioned anywhere in your C++ code.


-- 
                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution





More information about the Cplusplus-sig mailing list