[C++-sig] Returning std::vector<int*> to python

Linh.H.Phan@jpl.nasa.gov phan at grover.jpl.nasa.gov
Sun Sep 18 03:09:33 CEST 2005


Hi,

  I'm having a problem returning a std::vector<int*> to python:

#include <vector>
typedef std::vector<int*> intVec;
class Node
{
public:
  Node() {}
  intVec& getIntVec() {
    return intvec;
  }
  int computeSum(const intVec& intvec) {return 1;}
  intVec intvec;
};

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python.hpp>
using namespace boost::python;

BOOST_PYTHON_MODULE(hello)
{
    class_<Node>("Node", init<>())
      .add_property("intvec"
        , make_getter(&Node::intvec, return_internal_reference<>()))
      .def("getIntVec", (intVec&(Node::*)())&Node::getIntVec,
	   return_internal_reference<>())
      .def("computeSum", &Node::computeSum)
    ;
}

>>> import hello
>>> test = hello.Node()
>>> test.computeSum(test.intvec)
TypeError: No Python class registered for C++ class std::vector<int*, std::allocator<int*> >
>>> test.computeSum(test.getIntVec())
TypeError: No Python class registered for C++ class std::vector<int*, std::allocator<int*> >
>>> 

Can someone please help?

Thank you very much!

Linh



More information about the Cplusplus-sig mailing list