Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-11-08 09:26:00


Dan Nuffer <dnuffer_at_[hidden]> writes:

> 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

Oh, I'm guessing that this is due to the odd status of const
char*. I'll look into it.

In the meantime, is it practical for you to use std::string instead of
const char*?

-- 
                       David Abrahams
   dave_at_[hidden] * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

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