implicit conversion

Discussion in 'Python' started by Benjamin Schmeling, Jan 31, 2005.

  1. Hi,

    I am working on exposing a bigint class to python. Now I've got the
    problem that methods which take an bigint as
    an parameter do not accept Python longs.

    For example:
    import _PythonLiDIA
    x=123L;
    c=_PythonLiDIA.bigint();
    _PythonLiDIA.gcd(c,x);


    Traceback (most recent call last):
    File "test.py", line 132, in ?
    _PythonLiDIA.gcd(a,x);
    Boost.Python.ArgumentError: Python argument types in
    _PythonLiDIA.gcd(bigint, long)
    did not match C++ signature:
    gcd(LiDIA::bigint, LiDIA::bigint)

    I don't know how to achieve implicit conversion at this point, turning an
    long automatically into an bigint. The other way round, turning an bigint
    into long can be realized by defining __long__.

    Can someone help me please?

    Benjamin
    Benjamin Schmeling, Jan 31, 2005
    #1
    1. Advertising

  2. Benjamin Schmeling <> wrote:
    ...
    > I don't know how to achieve implicit conversion at this point, turning an
    > long automatically into an bigint. The other way round, turning an bigint
    > into long can be realized by defining __long__.


    Perhaps adding to your bigint class a constructor (not declared as
    ``explicit'', if you're coding C++) which accepts as its argument a
    python long might help...?


    Alex
    Alex Martelli, Jan 31, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jacob
    Replies:
    7
    Views:
    404
    Dale King
    Oct 3, 2003
  2. dmoos AT esigma-systems DOT de

    implicit vs. explicit type conversion for string vs. (char *)

    dmoos AT esigma-systems DOT de, Jun 26, 2003, in forum: C++
    Replies:
    2
    Views:
    2,496
    Default User
    Jun 26, 2003
  3. Russell Reagan

    Implicit conversion is evil?

    Russell Reagan, Oct 27, 2003, in forum: C++
    Replies:
    2
    Views:
    308
    Russell Reagan
    Oct 27, 2003
  4. al
    Replies:
    2
    Views:
    5,591
    Ernst Murnleitner
    Jan 7, 2004
  5. Boris
    Replies:
    3
    Views:
    403
Loading...

Share This Page