[C++-sig] Boost.Python and abstract class...

Baptiste Lepilleur gaiacrtn at free.fr
Sat Apr 5 10:02:51 CEST 2003


Thanks for your reply. I finally figured it out when rereading the doc. I
was doing:

 class_<Base, BaseWrap, boost::noncopyable>("Base", no_init);  // (first
code sample)

instead of :

class_<Base, BaseWrap, boost::noncopyable>("Base");

It's now working correctly. Though, the tutorials on present the second form
as a way to avoid having to redefine the constructor in python.

Baptiste.

----- Original Message -----
From: "Pierre Barbier de Reuille" <pierre.barbier at cirad.fr>
To: <c++-sig at python.org>
Sent: Thursday, April 03, 2003 10:54 AM
Subject: Re: [C++-sig] Boost.Python and abstract class...


> Just don't look at the web site's tutorial : only refer to the one in
> your boost directory !
>
> Pierre
>
> Baptiste Lepilleur wrote:
> >     Hi all,
> >     I'm a newbie to Boost.Python and I'm trying to expose an abstract
class
> > to python, as demonstrated in "Class Virtual Functions" of the tutorials
> >
(http://boost.org/libs/python/doc/tutorial/doc/class_virtual_functions.html)
> > .
> >
> >     If I try the code provided in the tutorial, I get the following
error:
> >
> >
> >>>>class Derived(Base):
> >
> > ...   def f(self):
> > ...     return 42
> > ...
> >
> >>>>d = Derived()
> >
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> > RuntimeError: This class cannot be instantiated from Python
> >
> >     I fixed this by adding a constructor:
> >
> >
> >>>>class Derived(Base):
> >
> > ...   def __init__(self):
> > ...     pass
> > ...   def f(self):
> > ...     return 42
> > ...
> >
> >>>>d = Derived()
> >>>>call_f(d)
> >
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> > TypeError: bad argument type for built-in operation
> >
> >     But then I get the above error. If I make the Base class non
abstract
> > and expose it without boost::noncopyable and no_init, then call_f works
> > correctly.
> >
> >    Works (with making Base non abstract):
> >    class_<Base, BaseWrap>("Base");
> >
> >     Don't work (see above):
> >     class_<Base, BaseWrap, boost::noncopyable>("Base");
> >
> >     I'm using VC6 SP5 and Boost 1.30.
> >
> >     Anyone knows what is wrong ?
> >
> >     Baptiste.
> >
> >
> >
> > _______________________________________________
> > C++-sig mailing list
> > C++-sig at python.org
> > http://mail.python.org/mailman/listinfo/c++-sig
> >
>
>
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>






More information about the Cplusplus-sig mailing list