what's difference usage?

momobear wgwigw at gmail.com
Sun Sep 28 03:53:54 CEST 2008


while as I try to wrap a function using boost-python, I find a strange
situation.
#include <iostream>
#include <string>
#include <vector>
#include <boost/python/list.hpp>
#include <boost/python.hpp>

using namespace boost::python;

int printlist(list &l){
	std::vector<std::string> a;
	a.push_back("c++");
	a.push_back("javascript");
	for (std::vector<std::string>::iterator p = a.begin(); p != a.end(); +
+p)
		l.append(*p);
       return 0;
}

BOOST_PYTHON_MODULE(wlist){
       def("printlist", printlist);
}

in the up code,"int printlist(list &l)" at first time I missed add &
left of l. but when I run the following python code,
#!/usr/local/bin/python
a = list()
a.append('linux')
import wlist
wlist.printlist(a)
print a

they get the same result.
linux
c++
javascript

anyone help me figure out what's wrong here. thanks.



More information about the Python-list mailing list