[C++-sig] Re: Why the document example can't be compiled?
David Abrahams
dave at boost-consulting.com
Tue Dec 23 16:02:52 CET 2003
guan bin <gb0519 at hotmail.com> writes:
> Hi,
>
> I've read the document below:
> /boost/libs/python/doc/tutorial/doc/extracting_c___objects.html
>
> and want to get a boost::python::list object's length
> so I write the following code:
> -----------------------------------------------------------
> #include "boost/python/list.hpp"
>
> using namespace boost::python;
> void PriList(list lst)
> {
> int x = extract<int>(lst.attr("__len__")());
> // int y = extract<int>(lst.attr("__len__")())();
> }
>
> #include <boost/python/module.hpp>
> #include <boost/python/def.hpp>
>
> BOOST_PYTHON_MODULE(GTest)
> {
> def("PList", PriList);
> }
> --------------------------------------------------------
> when I compile it, I get the following errors:
> ----------------------------------------------------------
> D:\samples\boost\python>bjam
> ...found 969 targets...
> ...updating 4 targets...
> vc-C++ bin\GTest.pyd\msvc\debug\runtime-link-dynamic\test.obj
> test.cpp
> test.cpp(6) : error C2440: 'type cast' : cannot convert from 'class
> boost::pytho
> n::api::object' to 'struct boost::python::extract<int>'
> Source or target has incomplete type
> e:\boost\boost/python/args_fwd.hpp(43) : fatal error C1506:
> unrecoverable block
> scoping error
> ------------------------------------------------------------------
> after I read the doc below:
> http://mail.python.org/pipermail/c++-sig/2003-September/005510.html
> I change the code
> int x = extract<int>(lst.attr("__len__")()); ------>
> int x = extract<int>(lst.attr("__len__")())();
> but the error still exist.......
>
> Who can help me ? Thanks advance.
You're missing some #includes, notably
#include "boost/python/extract.hpp"
HTH,
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list