title: How to overload operators with Boost.Python
body: <p>I am trying to overload operators of a C++ class using Boost.Python.</p>
  
  <p>According to <a href="http://www.boost.org/doc/libs/1_40_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.class_operators_special_functions" rel="nofollow noreferrer" title="this">this</a>, I am doing it the right way... but I have a bunch of compiler errors.</p>
  
  <p>Here is a simple example I made trying to pinpoint the problem:</p>
  
  <pre><code>#include "boost/python.hpp"
  
  using namespace boost::python;
  
  class number
  {
  public:
      number(int i) : m_Number(i) { }
      number operator+(int i) { return number(m_Number + i); }
  private:
      int m_Number;
  };
  
  BOOST_PYTHON_MODULE(test)
  {
      class_&lt;number&gt;("number", init&lt;int&gt;())
          .def(self() + int());
  }
  </code></pre>
  
  <p>Here are the compiler errors:</p>
  
  <pre><code>Error   1   error C2064: term does not evaluate to a function taking 0 arguments    c:\users\kevin\documents\visual studio 2008\projects\boostpythontest\boostpythontest\test.cpp   16  BoostPythonTest
  Error   2   error C2780: 'boost::python::class_&lt;W&gt; &amp;boost::python::class_&lt;W&gt;::def(const char *,Fn,const A1 &amp;,const A2 &amp;,const A3 &amp;)' : expects 5 arguments - 1 provided c:\users\kevin\documents\visual studio 2008\projects\boostpythontest\boostpythontest\test.cpp   16  BoostPythonTest
  Error   3   error C2780: 'boost::python::class_&lt;W&gt; &amp;boost::python::class_&lt;W&gt;::def(const char *,Fn,const A1 &amp;,const A2 &amp;)' : expects 4 arguments - 1 provided    c:\users\kevin\documents\visual studio 2008\projects\boostpythontest\boostpythontest\test.cpp   16  BoostPythonTest
  Error   4   error C2780: 'boost::python::class_&lt;W&gt; &amp;boost::python::class_&lt;W&gt;::def(const char *,A1,const A2 &amp;)' : expects 3 arguments - 1 provided   c:\users\kevin\documents\visual studio 2008\projects\boostpythontest\boostpythontest\test.cpp   16  BoostPythonTest
  Error   5   error C2780: 'boost::python::class_&lt;W&gt; &amp;boost::python::class_&lt;W&gt;::def(const char *,F)' : expects 2 arguments - 1 provided   c:\users\kevin\documents\visual studio 2008\projects\boostpythontest\boostpythontest\test.cpp   16  BoostPythonTest
  </code></pre>
  
  <p>Am I missing something here ?</p>
  
  <p>Thanks</p>