[C++-sig] passing raw pointers of interface impls

David Abrahams dave at boost-consulting.com
Thu Jan 9 19:33:21 CET 2003


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.

>       return
>    def create(self, b):
>       return A(b)
>
> factory = Factory()
> c = CreatorImpl()
> factory.reg(c)
>
> b = B()
> a = factory.create(b)

-- 
                       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