[C++-sig] Abstract classes

Shin-ichi MORITA shin1_morita at yahoo.co.jp
Wed Jun 30 17:03:09 CEST 2004


Hi,

> Paul wrote:
> 
> > Pyste was generating constructors defs for
> abstract classes. 
> > I've changed 
> > Pyste so that it will insert no_init (and emit no 
> > constructors) for abstract 
> > classes.
> > 
> > Is this the correct behaviour for an abstract
> class?
> > eg.
> > class_< Foo, boost::noncopyable>("Foo", no_init)
> > 
> > This from the FAQ states this quite clearly:
> >
>
http://www.python.org/cgi-bin/moinmoin/boost_2epython_2fFAQ
> > >     * no_init means "do not try to create an
> instance of 
> > that Python object, create __init__ function that
> throws an exception"
> > >     * noncopyable means "do not try to register
> a converter 
> > which can convert C++ return values of that class
> to Python". 
> > > 
> > > When wrapping an abstract class, it's necessary
> to specify both. 
> > 
> > However, what's confusing me is that I thought
> specifying 
> > no_init would make 
> > the following incorrect:
> > 
> > class Bar(CppModule.Foo):
> > 	def __init__(self):
> > 		CppModule.Foo.__init__(self)
> > 
> > Is that correct?
> 
> I think this is correct. Abstract class has
> constructors. 
> 
> Roman

I think CppModule.Foo.__init__(self) simply throws an
exception (because of no_init).
Thus Bar cannot be instantiated.

For now, __init__ must be called to initialize Python
instance correctly, no matter whether the exposed class is
abstract or not:

   
http://mail.python.org/pipermail/c++-sig/2004-June/007522.html

shin


__________________________________________________
Do You Yahoo!?
http://bb.yahoo.co.jp/





More information about the Cplusplus-sig mailing list