Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-07-17 12:18:58


----- Original Message -----
From: <Peter.Bienstman_at_[hidden]>
> Consider
>
> class_builder<Term> Term_(module, "Term");
> Term_.def(constructor<>());
>
> class_builder<Expression> Expression_(module, "Expression");
> Expression_.def(constructor<>());
> Expression_.def(constructor<const Term&>());
>
> class_builder<User> User_(module, "User");
> User_.def(constructor<const Expression&>();
>
> Using the original C++ code, I could write
>
> Term t=Term();
> User u=User(t);
>
> , because C++ is smart enough to figure out how to construct an
> Expression from a Term.
>
> Now, trying the same in Python, we get
>
> >>>t = Term()
> >>>u = User(t)
>
> TypeError: extension class 'Term' is not convertible
> into 'Expression'.
>
> Short of modifying the original C++ code to add a User::User(const
> Term&) constructor, is there anything I can do to get the Boost
> typesystem to apply Expression::Expression(const Term&) for me?

I am assuming that Term can be implicitly converted to (but is not derived
from) Expression here. I think that in this case, you can just add the
following:

  User_.def(constructor<const Term&>);

OTOH, that will only work for constructors. I think that getting it to work
for other functions in general is a problem closely related to the default
arguments issue also explored here recently.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk