A quick question, I've moved onto operator overlaoding, and I have noticed that sometimes the overlaod is with and & and sometimes not? Question is what are the rules for using the &
Integer &operator ++();
increments a variable and returns a reference to the incremented variable
Integer operator ++(int);
copies a variable. increments it, and returns a copy of the new value (doesnt upset the original)
Integer & operator =(Integer &&a);
this is a move operator, you still need to use std::move() unless returning the value which will automatically perform the move. integers are a bad example, try it with a class object.
basic rules...
there aren't any really, each example performs diffferent functionality and its for you to choose the one you want.
eg; you're first example increments a variable in memory then returns a reference to that instead of copying it.
you're second example reads a variable, increments it and returns that modified copy, so its not a ref.
Hi thanks for your answers - Integer is a basic class that I have written. I will search the internet to see if I can find any further information on when to/not use &