[C++-sig] passing raw pointers of interface impls
David Abrahams
dave at boost-consulting.com
Fri Jan 10 05:15:00 CET 2003
Ben Scott <bscott at iastate.edu> writes:
> David Abrahams wrote:
>> Ben Scott <bscott at iastate.edu> writes:
>>
>>>I have been quite happily enjoying the ease at which Boost.Python v2
>>>has been allowing me to export C++ libraries to Python. Thank you Dave
>>>for your excellent work!
>>>
>>>However, I've gotten stumped on the attached bit of code. I'm
>>>unfortunately getting the ambiguous "bad argument type for built-in
>>>operation" TypeError. I've reviewed the tutorial and references
>>>(including the last couple months of this list) but am at a loss to
>>>explain why c is of the wrong type. Any ideas on the matter would be
>>>most helpful.
>>>
>>>Here's the output of simple.py:
>>>Traceback (most recent call last):
>>> File "./simple.py", line 12, in ?
>>> factory.reg(c)
>>>TypeError: bad argument type for built-in operation
>>>
>>>
>>>class CreatorImpl(Creator):
>>> def __init__(self):
>> Right here, you need to call Creator.__init__(self)
>> to create the C++
>> base class instance. Of course, you could just leave out the __init__
>> function here altogether and let the base __init__ get called.
>
> Yeah, I had tried that, but since Creator is an
> abstract type it can't be instantiated as you are
> suggesting.
You have to remove the no_init from the class_<CreatorWrap>
declaration.
> This of course causes the "RuntimeError:
> This class cannot be instantiated from Python" error
> from the default __init__ in Creator that BPL defines.
One of these days, we'll have the __init__ function generated by
no_init check the actual Python class being created to make sure it's
not the base type (Creator, in this case). Until then, just leave out
no_init and you'll be fine.
--
David Abrahams
dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution
More information about the Cplusplus-sig
mailing list