[C++-sig] passing raw pointers of interface impls
Ben Scott
bscott at iastate.edu
Fri Jan 10 05:02:23 CET 2003
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. This of course causes the
"RuntimeError: This class cannot be instantiated from Python" error from
the default __init__ in Creator that BPL defines.
>
>
>> return
>> def create(self, b):
>> return A(b)
>>
>>factory = Factory()
>>c = CreatorImpl()
>>factory.reg(c)
>>
>>b = B()
>>a = factory.create(b)
>
>
cheers,
-----
Ben Scott
Research Assistant
VR Juggler Team
Virtual Reality Applications Center
bscott at vrac.iastate.edu
More information about the Cplusplus-sig
mailing list