title: Confused about operator overloading
body: <p>As I progress on my little math library I'm stumbling upon certain aspects of C# and the .NET Framework that I'm having some trouble understanding.</p>
  
  <p>This time it's operator <em>overloading</em> and specifically the term <em>overloading</em> itself. Why is it called <em>overloading</em>? Do all objects by default have an implementation of all operators? That is, is:</p>
  
  <pre><code>public static object operator +(object o1, object o2)
  </code></pre>
  
  <p>predefined somewhere and somehow? If so, why then if I try <code>o1 + o2</code> I get the compile time error <code>Operator '+' cannot be applied to operands of type 'object' and 'object'</code>? This would somehow imply that by default objects do not have predefined operators so then how come the term <em>overloading</em>?</p>
  
  <p>I ask this, because in my math library, working with 3D geometry elements, I have the following structs: <code>Vector</code> and <code>Point</code>. Now, internally I want to allow the following construct to create vectors:</p>
  
  <pre><code>static Vector operator -(Point p1, Point p2) {...}
  </code></pre>
  
  <p>As this is not mathematically 100% correct but very useful internally to reduce code clutter, I don't want to expose this operator publicly, so my initial intention was to simply do:</p>
  
  <pre><code>internal static Vector operator -(Point p1, Point p2) {...}
  </code></pre>
  
  <p>Surprisingly (for me) I got the following compile time error: <code>User-defined operator 'Geometry.operator +(Geometry.Vector, Geometry.Vector)' must be declared static and public</code>".</p>
  
  <p>Now this restriction that all operators must be public <em>does</em> seem to make some sense with the whole <em>overloading</em> aspect of operators but it seems that it is all kind of inconsistent:</p>
  
  <ol>
  <li>Objects by default do not have predefined operators: I can't do <code>object + object</code> by default or <code>myTpye + myType</code> without explicitly defining the <code>+</code> operator beforehand.</li>
  <li>Defining operators is not described as creating an operator, it's described as <em>overloading</em> which somehow is inconsistent (to me) with point 1.</li>
  <li>You cannot restrict access modifier of an <code>operator</code>, they have to be <code>public</code>, which does not make sense considering point 1. but sort of makes sense considering point 2.</li>
  </ol>
  
  <p>Can somebody explain the mess I'm making of all this in simple terms?</p>