Compilation failed when making use of %template of std::map,
when the value of the std::map is a pointer to class instance.
%template of std::vector works, and even make the %template of std::map work.
For example:
%module demo
%{
#define SWIG_FILE_WITH_INIT
class Foo {
public:
Foo(){};
};
%}
%include "std_vector.i"
%include "std_map.i"
/* %template(vector_Foo) std::vector<Foo*>; */
%template(map_Foo) std::map<int,Foo*>;
class Foo {
public:
Foo();
};
Using Swig 2.0.4, this example doesn't compile, unless the line '%template(vector_Foo)' is uncommented.
Error is:
demo_wrap.cpp: In function ‘const char* swig::type_name() [with Type = Foo]’:
demo_wrap.cpp:3201: instantiated from ‘static swig_type_info* swig::traits_info<Type>::type_info() [with Type = Foo]’
demo_wrap.cpp:3208: instantiated from ‘swig_type_info* swig::type_info() [with Type = Foo]’
demo_wrap.cpp:3242: instantiated from ‘static PyObject* swig::traits_from_ptr<Type>::from(Type*, int) [with Type = Foo]’
demo_wrap.cpp:3254: instantiated from ‘static PyObject* swig::traits_from<Type*>::from(Type*) [with Type = Foo]’
demo_wrap.cpp:3267: instantiated from ‘PyObject* swig::from(const Type&) [with Type = Foo*]’
demo_wrap.cpp:4542: instantiated from here
demo_wrap.cpp:3191: error: ‘type_name’ is not a member of ‘swig::traits<Foo>’
It seems that the problem was solved in swig-1.3.33:
http://old.nabble.com/std::map-and-python-td15206781.html
http://comments.gmane.org/gmane.comp.programming.swig/9472
I can confirm this for swig-2.0.4. Couldn't test with 2.0.7 because of some other bug.
The old workaround still works.
Duplicate of https://sourceforge.net/p/swig/bugs/1235/