title: How to define asymmetric + operator
body: <p>Why does this not work? I'm trying to define the + operator for int+Date and make it return an int. So I define the operator+ as a member to define Date+int, and I define a non-member function operator+(int, Date), but when using it in the main it doesn't seem to use that function and generates an error</p>
  
  <pre><code>class Date
  {   int D;
      int M;
      int Y;
  public:
      Date();
      Date(int, int, int);
      ~Date(void);
      int getDay() const;
      Date operator+(Date) const;
      Date operator+(int) const;
  };
  
  Date::Date()
  {
      D = 15;
      Y = 2012;
      M = 2;
  }
  Date::Date(int d, int m, int y)
  {
      D = d;
      Y = y;
      M = m;
  }
  Date::~Date(void)
  {
  }    
  int Date::getDay() const
  {
      return D;
  }
  Date Date::operator+(Date d) const
  {
      return Date(d.D+D,d.M+M,d.Y+Y);
  }
  Date Date::operator+(int d) const
  {
      return Date(d+D,M,Y);
  }
  
  int operator+(int i,Date d) // This is what is wrong apparently.
  {
      return i + d.getDay();
  }
  
  int main ()
  {
  Date d = Date();
  int i = 7 + d; // This is what generates the error at compile time.
  cout &lt;&lt; i;
  return 0;
  }
  </code></pre>