[C++-sig] Re: How to extract a sublist from a list in C++ ?

David Abrahams dave at boost-consulting.com
Thu Dec 9 00:30:13 CET 2004


pj wrote:
>> PJ Durai wrote:
>> > Greetings,
>> >
>> > I couldnt figure out the following bit.
>> >
>> > Say I am passing a list of lists.   [ [a, b] , [c,d]]  to a method in a
> C++
>> > object.
>> >
>> > In the C++ class,
>> >
>> > void ParseList (list lst)
>> > {
>> >    object o = lst[0];
>>
>> What about
>>
>>      list l1(lst[0])
> 
> Cool! That works. Thanks !
> 
>>
>> ??
>>
>> >    // how do I conver 'o' to a list again?
>> >    list l1  = extract<list> (o);   <- naive attempt. but doesnt work.
>>
>> What happens?
> 
> Compiler error.
> 
> UnittestGlue.cpp
> C:\Pioneer\ADAPTERS\NOTES\UnittestGlue.cpp(367) : error C2440:
> 'initializing' : cannot convert from 'struct boost::python::extract<class
> boost::python::list>' to 'class boost::python::list'
>         No constructor could take the source type, or constructor overload
> resolution was ambiguous
> 
> My setup:
> 
> Visual C++ 6  SP4
> Windows 2000 Pro SP4
> Boost 1.2.30

Oh, well... with vc6 lots of otherwise-valid usages are crippled.  Try

   list l1  = extract<list>(o)();
                              ^^
Cheers :)
-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com




More information about the Cplusplus-sig mailing list