title: Wrapping a C++ class in Python using SWIG
body: <p><strong>example.h</strong>:</p>
  
  <pre><code>#ifndef EXAMPLE_H
  #define EXAMPLE_H
  
  class Math {
   public:
      int pi() const;
      void pi(int pi);
   private:
      int _pi;
  };
  
  #endif
  </code></pre>
  
  <p><strong>example.cpp</strong>:</p>
  
  <pre><code>#include "example.h"
  
  int Math::pi() const {
      return this-&gt;_pi;
  }  
  void Math::pi(int pi) {
      this-&gt;_pi = pi;
  }
  </code></pre>
  
  <p><strong>example.swig</strong>:</p>
  
  <pre><code>%module example
  %{ 
      #define SWIG_FILE_WITH_INIT
      #include "example.h"
  %}
  %include "example.h"
  </code></pre>
  
  <p>I then generate the wrappers, "example.py" and "example_wrap.c" using:</p>
  
  <pre><code>swig  -python example.swig
  </code></pre>
  
  <p>When I try to compile the wrapper class using:</p>
  
  <pre><code>g++ -fPIC -c example.cpp example_wrap.c -I/usr/local/include/python2.6/
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>example_wrap.cpp: In function "PyObject* Swig_var_Math_get()":
  example_wrap.cpp:2725: error: expected primary-expression before "void"
  example_wrap.cpp:2725: error: expected ")" before "void"
  </code></pre>
  
  <p>The Error is at the following line :</p>
  
  <pre><code>pyobj = SWIG_NewPointerObj(SWIG_as_voidptr(&amp;Math), SWIGTYPE_p_class,  0 );
  
  #define SWIG_as_voidptr(a) (void *)((const void *)(a))
  </code></pre>
  
  <p>Is it the right way to generate the wrapper class "example_wrap.c"?</p>