title: Swig shared_ptr macro with templated class and derived classes
body: <p>This question is in some ways an extension of the question posted here:
  <a href="https://stackoverflow.com/questions/5559147/swig-shared-ptr-macro-with-templated-class/11380432#11380432">SWIG_SHARED_PTR macro with templated class</a>
  Although perhaps the issue is entirely unrelated.</p>
  
  <p>The basic set up is this: I am trying to get SWIG to wrap a templated class as a shared_ptr. So the interface file should look something like this</p>
  
  <pre><code>%shared_ptr(template_instance)
  %include template_class.cpp
  %template(vector_instance) template_class&lt;int&gt;;
  </code></pre>
  
  <p>Now the problem is that <code>template_class</code> has a lot of derived classes, this causes a lot of warnings in swig, and then build errors. These classes do not need to be handled as <code>shared_ptr</code>'s, so I would rather just ignore the warnings the above code generates. The solution to the error seems to be:</p>
  
  <pre><code>%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&lt;int&gt;;
  </code></pre>
  
  <p>This works, but is a huge mess, and I assume there must be some disadvantage to having everything represented as a shared_ptr (what is it?). Is there anyone around this?</p>
  
  <p>EDIT: UPDATE WITH SPECIFIC EXAMPLE</p>
  
  <p>test.h</p>
  
  <pre><code>class Base
  {
    int base_member;
  };
  
  class Derived : public Base
  {
    int derived_member;
  };
  </code></pre>
  
  <p>test.i</p>
  
  <pre><code>%module test
  %{
  #include "test.h"
  #include &lt;boost/shared_ptr.hpp&gt;
    %}
  
  %include &lt;boost_shared_ptr.i&gt;
  %shared_ptr(Base)
  %include test.h
  </code></pre>
  
  <p>commands:</p>
  
  <pre><code>swig -python -c++ test.i 
  g++ -fPIC -I /usr/include/python2.7 -c test_wrap.cxx
  </code></pre>
  
  <p>In this stripped down example, the swig call gives warnings, and the g++ call gives errors. Note that I've removed the templating, as it didn't seem to be an ingredient in the problem.</p>
  
  <p>The errors are resolved by commenting out </p>
  
  <pre><code>%shared_ptr(Base)
  </code></pre>
  
  <p>The warning generated by swig is:</p>
  
  <pre><code>test.h:10: Warning 520: Derived class 'Derived' of 'Base' is not similarly marked as a smart pointer
  </code></pre>
  
  <p>and the error from g++ is:</p>
  
  <pre><code>test_wrap.cxx: In function ‘PyObject* _wrap_delete_Derived(PyObject*, PyObject*)’:
  test_wrap.cxx:3155:22: error: ‘smartarg1’ was not declared in this scope
  </code></pre>