[C++-sig] Re: Doubts with wrapping/using abstract bases.

Raoul Gough RaoulGough at yahoo.co.uk
Sun Aug 10 21:28:50 CEST 2003


Prabhu Ramachandran <prabhu at aero.iitm.ernet.in> writes:

> Hi,
>
> I think I have a fairly serious misunderstanding of how Boost.Python
> wraps abstract virtual classes.  I'd appreciate any clarifications.
>
> Here is a simple example:
>
> // ---------------- holder.hpp ----------------------
> #include <vector>
> #include <iostream>
>
> struct A {
>     virtual ~A() {}
>     virtual void f()=0;
> };
[snip]
> BOOST_PYTHON_MODULE(holder)
> {
>     class_< A, boost::noncopyable, std::auto_ptr< A_Wrapper > >
>     ("A", init<  >());

Here's the problem - the Python reflection of class "A" does not
include the function f at all. You would need to get something like

class_< A, boost::noncopyable, std::auto_ptr< A_Wrapper > >
  ("A", init<  >())
  .def ("f", &A::f);

for the code to work. Not sure how to get pyste to do that though.

[snip]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> AttributeError: 'A' object has no attribute 'f'
>
> I did not expect this since this is perfectly legal in C++,
> i.e. b1->f() in C++ is legal and used commonly.  So what am I doing
> wrong?

How about adding the extra "def" manually to see whether it fixes the
problem? Sorry I can't help on the Pyste side of this. Mayeb some
semi-relevant stuff by Googling for pyste pure virtual.

-- 
Raoul Gough
"Let there be one measure for wine throughout our kingdom, and one
measure for ale, and one measure for corn" - Magna Carta





More information about the Cplusplus-sig mailing list