title: How to wrap a class derived from vector in swig
body: <p>I want to wrap a class derived from std::vector with some extend functions into csharp with swig. the functions from vector are also needed like push_back to add new item into the class (which named <code>Add</code> in csharp).</p>
  <p>I tried with default setting with swig, IntArray is valid in csharp .But, vector's functions are invalid.</p>
  <p>if i try to define a vector in the .i file:</p>
  <pre class="lang-cpp prettyprint-override"><code>namespace std{
  %template(ScalarVec) vector&lt;ScalarTest&gt;; 
  }
  </code></pre>
  <p>a class named ScalarVec have functions like vector is valid in csharp, but without the extend function.</p>
  <p><strong>How to wrap the ScalarArray to csharp with swig?</strong></p>
  <p>The following is a simple example.</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;vector&gt;
  #include &lt;numeric&gt;
  namespace test
  {
      struct ScalarTest {
          int val;
      };
      struct ScalarArray : public std::vector&lt;ScalarTest&gt;
      {
          int sum() const { 
              int res = 0;
              for (const ScalarTest &amp;item : *this) {
                  res += item.val;
              }
              return res;
          }
      };
  }
  </code></pre>