[C++-sig] [Boost.Python] map_indexing_suite problem

Jan Langer jan at langernetz.de
Fri Nov 18 18:42:18 CET 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,
I ran into a problem with Boost.Python exporting a std::map. I used the
following code below. I use Boost 1.33.0 and everything compiles fine.

>>>>>>>>>>>
#include <boost/python.hpp>
#include <boost/python/suite/indexing/map_indexing_suite.hpp>

using namespace boost::python;

typedef std::map <int, std::string> map_t;

struct A
{
  map_t data;
  std::string str;
};

BOOST_PYTHON_MODULE(test)
{
  class_ <map_t> ("test_map")
    .def (map_indexing_suite <map_t> ());

  class_ <A> ("A")
    .def_readonly ("data", &A::data)
    .def_readwrite ("str", &A::str);
}
<<<<<<<<<<<<

Then I run Python and try to use the module:

>>>>>>>>>>>>
laja at bridge:python> python
Python 2.4.1 (#1, Sep  2 2005, 09:48:20)
[GCC 2.95.2 19991024 (release)] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import test
>>> a = test.A()
>>> a.str="text"
>>> a.str
'text'
>>> a.data[0]="text2"
>>> a.data[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: No Python class registered for C++ class
t12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b0i0
<<<<<<<<<<<<

I played around for a while but I find no solution.
Regards,
Jan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (SunOS)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDfhJ5yJOS3PG4wcwRAihcAJsFhjuOtOykJlyC9JKsg1yobwOsKgCgxQa5
l6GQlwbGXfjizZ3BVVo81Io=
=Jebw
-----END PGP SIGNATURE-----




More information about the Cplusplus-sig mailing list