[C++-sig] wrapping objects which inherit from std::map

Stefan Seefeld seefeld at sympatico.ca
Wed May 6 19:29:59 CEST 2009

Jeremy Kie wrote:
> Hi,
> I have the following:
> class foo : public std::map<std::string, std::string> {
> }

You lack a semicolon here. (I also don't think it's a good idea to 
derive from standard containers, but that is an entirely different subject).

> {
>   using namespace boost::python;
>   class_<foo, bases<std::map>>("foo");

There are three errors here, let's start with the simplest:

You use '>>' in this line, which is a single token. You need to insert a 
whitespace there to make it two tokens, e.g. '> >'.
Next, you use 'std::map' where you ought to use a type (such as 
'std::map<std::string, std::string>'.
Finally, you only can declare bases that are themselves already exported 
to python via class_, so you need to start by exporting the base type 
std::map<std::string, std::string> prior to 'foo'.

Hope this helps,


      ...ich hab' noch einen Koffer in Berlin...

More information about the Cplusplus-sig mailing list