[C++-sig] vector of shared_ptr ?
Chad Austin
caustin at gmail.com
Tue Nov 9 05:14:02 CET 2004
I am trying to export a vector of smart pointers to Python using
vector_indexing_suite. Here is a test case:
// Begin C++ Code
#include <boost/shared_ptr.hpp>
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <vector>
using namespace boost;
using namespace boost::python;
class A {
};
typedef shared_ptr<A> APtr;
typedef std::vector<APtr> AList;
BOOST_PYTHON_MODULE(ptrvector) {
class_<A, APtr>("A")
;
register_ptr_to_python<APtr>();
class_<AList>("AList")
.def(vector_indexing_suite<AList>())
;
}
// End C++ Code
I would expect the following test case to succeed:
# Begin Python Code
from ptrvector import *
a = AList()
a[:] = [A()]
for b in a:
print b
# End Python Code
However, I get an error:
$ python test.py
Traceback (most recent call last):
File "test.py", line 4, in ?
for b in a:
TypeError: No Python class registered for C++ class boost::shared_ptr<A>
Is this a known bug? Is there anything I can do to work around or fix this?
Thanks,
Chad
More information about the Cplusplus-sig
mailing list