@Catfish666 (602): References cannot change the variable they're referencing. |
Questions:
1. So references are constant variables? They seem to have the same behaviour..
2. But references store variables address, right? So, how do we use a reference in an expression? (sorry, to be completely sure)
3. If we use a constant reference as argument of a function we don't want that this function change the value of the referenced variable, otherwise every change to the reference is verified also on the referenced variable, right?
But we can't, as you said, make the reference "point" to another variable. This is also for contexts outside arguments of functions?
4. What are the best ways to pass a reference of a variable as argument of a function, with pointers or references? It depends as
said on what we want to do...
So this rules could be ok right?
rules of CodeGazer: Now I generally follow the rule of if I know that I possibly might need to point to multiple different objects using only one variable I will use a pointer, also if I know that there is a chance that I don't need to point to anything I will also use a pointer. For all other cases I will use references. |
5. If we want to pass a big object object as parameter of a function, what is the best way to do it: with pointers, references or simply pass all the object?