Can you explain to me the difference between returning value, reference to value, and const reference to value?
Value:
Vector2D oper
Value:
Returning by value means that you are returning a copy of an object. This puts requirements on the class (it has to be copyable or moveable). This means that for object of some classes returning by value may be expensive (in a case where RVO or NRVO does not work or is switched off). This also means that the new object is independent (subject to its design) from other objects and is a value of its own. This is what you probably should return from many binary operators like +, -, * and so on.
Non-const reference:
You really return an alias for another object. The alias being non const allow you to modify aliased object. This is what you should return from some unary oprators like prefix ++ and --, and * (dereference) as you usually want to have the ability to modify returned object.
This is returned by operator>> and operator<< overloaded for streams. This allows chaining of operators:
cout << 5 << "is greater then" << 1 << endl;
cin >> myInt >> myFloat;
You can also return reference to *this when you want to allow chaining of regular methods like this:
object.run().printLastRunStatistics();
Const reference:
Like above but you CANNOT modify aliased object. May be used instead of returning by value when the object to be returned is expensive to copy and when you can ensure its existence after you return from a function.
This is what operator= usually returns to allow multiple assignments in a way standard types support them:
a = b = c;
Const-reference used in operator= prevents this kind of usage (not supported by standard type as far as I remember):
++(a = b);
which would be allowed if normal reference was used.