what's difference usage?

M

momobear

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Python and STL efficiency 83
Vector iterator problem 3
TF-IDF 1
what's wrong in my code?!? 5
Query regarding iterators and vector 7
boost 2
sandbox python via module loader 0
Deleting first element of a linked list 4

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top