This question is in some ways a continuation of the question posted here: macro SWIG_SHARED_PTR with the template Although, perhaps, the problem is completely unrelated.
The basic setup is this: I'm trying to get SWIG to wrap a template class as shared_ptr. Thus, the interface file should look something like this.
%shared_ptr(template_instance) %include template_class.cpp %template(vector_instance) template_class<int>;
Now the problem is that template_class has many derived classes, this causes a lot of warnings in swig and then generates errors. These classes should not be treated as shared_ptr , so I would rather just ignore the warnings that the code above generates. The solution to the error is as follows:
%shared_ptr(template_derived1) %shared_ptr(template_derived2) . . . %shared_ptr(template_derivedn) %shared_ptr(template_instance) %include template_class.cpp %template(vector_instance) template_class<int>;
This works, but it's a huge mess, and I suppose there must be some kind of flaw for everything to be presented as shared_ptr (what is it?). Anyone about this?
EDIT: UPDATE WITH A SPECIFIC EXAMPLE
test.h
class Base { int base_member; }; class Derived : public Base { int derived_member; };
test.i
%module test %{ #include "test.h" #include <boost/shared_ptr.hpp> %} %include <boost_shared_ptr.i> %shared_ptr(Base) %include test.h
commands:
swig -python -c++ test.i g++ -fPIC -I /usr/include/python2.7 -c test_wrap.cxx
In the above example, a call to swig gives warnings, and a call to g ++ gives errors. Please note that I deleted the template as it did not seem to be an ingredient in the problem.
Errors are resolved by commenting.
%shared_ptr(Base)
Warning generated by swig:
test.h:10: Warning 520: Derived class 'Derived' of 'Base' is not similarly marked as a smart pointer
and error from g ++:
test_wrap.cxx: In function 'PyObject* _wrap_delete_Derived(PyObject*, PyObject*)': test_wrap.cxx:3155:22: error: 'smartarg1' was not declared in this scope