title: Can I override a C++ virtual function within Python with Cython?
body: <p>I have a C++ class with a virtual method:</p>
  
  <pre><code>//C++
  class A
  {
  
      public:
          A() {};
          virtual int override_me(int a) {return 2*a;};
          int calculate(int a) { return this-&gt;override_me(a) ;}
  
  };
  </code></pre>
  
  <p>What I would like to do is to expose this class to Python with Cython, inherit from this class in Python and have the correct overridden called:</p>
  
  <pre><code>#python:
  class B(PyA):
     def override_me(self, a):
         return 5*a
  b = B()
  b.calculate(1)  # should return 5 instead of 2
  </code></pre>
  
  <p>Is there a way to do this ? 
  Now I'm thinking, it could also be great if we could override the virtual method in Cython as well (in a pyx file), but allowing users to do this in pure python is more important.</p>
  
  <p><strong>Edit</strong>: If this helps, a solution could be to use the pseudocode given here: <a href="http://docs.cython.org/src/userguide/pyrex_differences.html#cpdef-functions">http://docs.cython.org/src/userguide/pyrex_differences.html#cpdef-functions</a></p>
  
  <p>But there are two problems then : </p>
  
  <ul>
  <li>I don't know how to write this pseudocode in Cython</li>
  <li>maybe there is a better approach</li>
  </ul>