Hi,

In the following test, we wrap a class "A" (and the class shared_ptr<A> using 
boost python facilites) and a function returning a vector of shared_ptr of this 
class (see test.cxx). The class "A" provides a display method. Creating an 
object of type "A" and calling the display method just works as expected.

The trouble (see test.py) is that calling the "display" method when iterating 
over the elements of the vector (of shared_ptr...) leads to the following 
message :

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    i.display()
Boost.Python.ArgumentError: Python argument types in
    A.display(A)
did not match C++ signature:
    display(A {lvalue})

Can anybody tell me if I misused the library ?

Sincerely,

Helfer Thomas

P.S. : This has been tested on Debian squeeze using python 2.6, boost 1.46 and 
1.48.
/*! 
 * \file  test.cxx
 * \brief
 * \author Helfer Thomas
 * g++ test.cxx -o test.so --shared -fPIC -L/path_to_boost/lib -I/usr/include/python2.6 -lboost_python -lpython2.6
*/

#include <vector>
#include <iostream>

#include <boost/shared_ptr.hpp>
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>

struct A
{
  void display()
  {
    std::cout << "test" << std::endl;
  }
};

std::vector<boost::shared_ptr<A> >
getVector()
{
  using namespace std;
  using namespace boost;
  typedef shared_ptr<A> ptr;
  return vector<ptr>(1,ptr(new A()));
}

BOOST_PYTHON_MODULE(test)
{
  using namespace std;
  using namespace boost;
  using namespace boost::python;

  class_<A,shared_ptr<A> >("A")
    .def("display",&A::display);

  class_<vector<shared_ptr<A> > >("AVector")
    .def(vector_indexing_suite<vector<shared_ptr<A> > >());

  def("getVector",getVector);

}
import test
a = test.getVector()

for i in a:
    i.display()


_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to