Boost logo

Boost :

From: Dan Nuffer (dnuffer_at_[hidden])
Date: 2002-11-08 02:01:08


David Abrahams wrote:
> Dan Nuffer <dnuffer_at_[hidden]> writes:
>>10. I added implicitly_convertible<const char*,OW_String>(); It
>>compiled fine, but it didn't work:
>> >>> import owclient
>> >>> s = owclient.OW_String("a")
>> >>> s.concat(owclient.OW_String("b"))
>><owclient.OW_String object at 0x817267c>
>> >>> s.c_str()
>>'ab'
>> >>> s.concat("c")
>>Traceback (most recent call last):
>> File "<stdin>", line 1, in ?
>>TypeError: bad argument type for built-in operation
>>
>>Any ideas why this didn't work?
>
>
> Not offhand. Can you post a small test case?
>

#include <boost/python.hpp>

using namespace boost::python;

struct test
{
     test() {}
     test(const char*) {}
     void foo(const test&) {}
};

BOOST_PYTHON_MODULE(test)
{
     class_<test>("test")
         .def(init<const char*>())
         .def("foo", &test::foo)
         ;

     implicitly_convertible<const char*,test>();
}

>>> import test
>>> t = test.test("foo")
>>> t.foo("fooagain")
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: bad argument type for built-in operation

HTH,
Dan Nuffer


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