Wrapping namespaced custom types defined only in headers with SWIG
<p>How can i wrap this content using SWIG?</p>

<p>usecase5.h</p>

<pre><code>#ifndef __USECASE5_H__
#define __USECASE5_H__

#include &lt;math.h&gt;

namespace foo_namespace {
    struct vec2
    {
        int x, y;

        vec2() {}

        explicit vec2( int a, int b )
        {
            x = a;
            y = b;
        }

        vec2 &amp; operator =( vec2  const &amp; v ) { x = v.x;  y = v.y;  return *this; }
        vec2 &amp; operator/=( vec2  const &amp; v ) { x /= v.x; y /= v.y; return *this; }

        vec2 xx() const { return vec2(x,x); }
    }
}

#endif
</code></pre>

<p>usecase6.h</p>

<pre><code>#ifndef __USECASE6_H__
#define __USECASE6_H__

#include "usecase5.h"

namespace foo_namespace {
    vec2  usecase6_f1(const vec2 &amp; x);
}

#endif
</code></pre>

<p>usecase6.cpp</p>

<pre><code>namespace foo_namespace {
    vec2  usecase6_f1(const vec2 &amp; x)
    {
        x = vec2();
    }
}
</code></pre>

<p>example.i</p>

<pre><code>// GENERATED BY gen_swig.py at 2016-10-04 21:46

%module example

%{
//#include "usecase1.h"
//#include "usecase2.h"
//#include "usecase3.h"
//#include "usecase4.h"
#include "usecase5.h"
#include "usecase6.h"

using namespace foo_namespace;
%}

//%include "usecase1.h"
//%include "usecase2.h"
//%include "usecase3.h"
//%include "usecase4.h"
%include "usecase5.h"
%include "usecase6.h"
</code></pre>

<p>After trying that naive example.i with <code>swig -python -c++ example.i</code> I'll get:</p>

<pre><code>usecase5.h(19) : Warning 362: operator= ignored
usecase5.h(24) : Error: Syntax error in input(3).
</code></pre>

<p>So, how could I wrap this little dummy c++ example?</p>

<p>It seems this wasn't any issue related with swig but more on the c++ side, to fix it I just needed to fix the c++ issues:</p>

<p>usecase5.h</p>

<pre><code>#ifndef __USECASE5_H__
#define __USECASE5_H__

#include &lt;math.h&gt;

namespace foo_namespace {
    struct vec2
    {
        int x, y;

        vec2() {}

        explicit vec2( int a, int b )
        {
            x = a;
            y = b;
        }

        vec2 &amp; operator =( vec2  const &amp; v ) { x = v.x;  y = v.y;  return *this; }
        vec2 &amp; operator/=( vec2  const &amp; v ) { x /= v.x; y /= v.y; return *this; }

        vec2 xx() const { return vec2(x,x); }
    };
}

#endif
</code></pre>

<p>usecase6.cpp</p>

<pre><code>#include "usecase5.h"

namespace foo_namespace {
    vec2  usecase6_f1(const vec2 &amp; x)
    {
        return x;
    }
}
</code></pre>

<p>After that the wrapper will be built succesfully and working properly on the python side.</p>

python c++ swig