[C++-sig] Why the document example can't be compiled?
guan bin
gb0519 at hotmail.com
Mon Dec 22 17:16:58 CET 2003
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.
My environment : win2000, vc6+sp5 , python2.2.3, boost-1.30.2
guanbin
2003.12.23
More information about the Cplusplus-sig
mailing list