[C++-sig] tutorial class_data_members compile problem

David Abrahams dave at boost-consulting.com
Tue Oct 15 18:14:34 CEST 2002


Chris Hoeppler <hoeppler at diener.iap.physik.uni-tuebingen.de> writes:

> On 15 Oct 2002, David Abrahams wrote:
> 
> > Christian Höppler <hoeppler at diener.iap.physik.uni-tuebingen.de> writes:
> >
> > > Hi,
> > >
> > > Being new to boost::python, I've just tried to build the class Var of the
> > > tutorial class_data_members.html.  However, I get the attached errors
> > > unless I remove the 'const' access modifier from its member variable
> > > 'name'.  In that case everything works just fine.
> > >
> > > What is the problem?
> >
> > Fixed now in CVS.
> 
> Thanx.
> 
> Meanwhile I've gotten a little further in the tutorial and ran
> into some other problems/questions/typos:
> 
> 
> class_properties.html:
> 
> -> I think all occurrances of "&Var::" should be replaced by "&Num::"
> 
> class_virtual_functions.html:
> 
> * At the point where the first version of Base is used in Python:
> 
>       In Python, let us try to instantiate our Base class:
> 
>       >>> base = Base()
>       AttributeError: ...
> 
>   -> I get a RuntimeError here
> 
> * continuing the example and trying to make an instance of the Python
>   class Derived, I also get a:
> 
>   RuntimeError: This class cannot be instantiated from Python

Right. It needs an __init__() function to suppress the Base class'
__init__. 


Hmm, I wonder if we should change that? It could check the object's
__class__ before raising that exception. That wouldn't prevent people
from instantiating subclasses that don't implement the pure virtual
functions, but that would be caught later by an AttributeError when
they try to call the function. Opinions?

> * Further on, with the second version of Base and BaseWrap I have to
>   include the boost::noncopyable parameter in the class_ template;
>   otherwise it won't compile

Hmm, good point.

> * Finally, towards the end of the example, calling call_f(base)
> results in
> 
>   TypeError: bad argument type for built-in operation


Hmm, that doen't sound right. What compiler/version are you using?

>   When rewriting that function as follows
> 
>     int call_f(Base *b) { return b->f(); }
> 
>   it works just fine.

Thanks,
-- 
           David Abrahams * Boost Consulting
dave at boost-consulting.com * http://www.boost-consulting.com





More information about the Cplusplus-sig mailing list