title: Cython: Syntax for overloading operators in cppclass objects
body: <p>I am trying to create a struct, or some other c-like object that can use operations such as "+", "-", "&lt;" etc</p>
  
  <p>My attempt to use the syntax is this:</p>
  
  <pre><code>cdef cppclass pair:
  double x
  double y
  pair operator+(pair&amp; other):   
      p = new pair()
      p[0].x = this.x+other.x
      p[0].y = this.y+other.y
      return p[0]
  cdef pair a
  cdef pair b
  a.x=1
  a.y=2
  b.x=3
  b.y=4
  cdef pair c
  c = a + b
  </code></pre>
  
  <p>but I get this error:</p>
  
  <pre><code>Error compiling Cython file:
  ------------------------------------------------------------
  ...
  
  cdef cppclass pair:
      double x
      double y
      pair operator+(pair&amp; other):   
  \.ipython\cython\_cython_magic_936ab3f7a1a67a849b882d3c497987c2.pyx:5:17: Syntax error in C variable declaration
  </code></pre>
  
  <p>It would also be nice to understand how to use the constructor as well, I noticed from <a href="http://cython-docs2.readthedocs.io/en/latest/src/userguide/wrapping_CPlusPlus.html?highlight=overloaded" rel="nofollow noreferrer">the docs</a> that there is functionality here, but without a working example I am unsure how to use it</p>
  
  <pre><code>cdef cppclass pair:
      double x
      double y
      pair(double x,double y)
  cdef pair* a
  a = new pair(1,2)
  </code></pre>
  
  <p>But I get a compiler error</p>
  
  <pre><code>\.ipython\cython\_cython_magic_054babde51af1aba9962dd2c57e823b2.cpp(1003) : error C2661: '__pyx_t_46_cython_magic_054babde51af1aba9962dd2c57e823b2_pair::__pyx_t_46_cython_magic_054babde51af1aba9962dd2c57e823b2_pair' : no overloaded function takes 2 arguments
  </code></pre>