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

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Sun Aug 10 21:46:29 CEST 2003


hi,

>>>>> "RG" == Raoul Gough <RaoulGough at yahoo.co.uk> writes:

    >> struct A { virtual ~A() {} virtual void f()=0; };
    RG> [snip]
    >> BOOST_PYTHON_MODULE(holder) { class_< A, boost::noncopyable,
    >> std::auto_ptr< A_Wrapper > > ("A", init< >());

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

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

I did not say so but that was the first thing I experimented with and
nope it does not work either.  Here is the error I get.

>>> import holder
>>> b = holder.B()
>>> h = holder.Holder ()
>>> h.add(b)
>>> b1 = h.get(0)
>>> b1.f()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
Boost.Python.ArgumentError: Python argument types in
    B.f(B)
did not match C++ signature:
    f(Q227_GLOBAL_.N.holder.cppNpcTEb9B_Wrapper {lvalue})
    f(1B {lvalue})

[snip]
    >> 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?

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

I think I should be able to add support for this quite easily in Pyste
and send in a patch but I don't think that is the problem here. :(

BTW, the tutorial never mentions that you do indeed need to "def" the
pure virtual function.

cheers,
prabhu




More information about the Cplusplus-sig mailing list