this is my first post. Please excuse the - maybe - confusing title. Learning c++ in my native language. Translation seems hard sometimes.
I'm trying to create two objects "a" and "b". With creation of object "b" I want to use object "a". I also want to change the object "a" by using the public functions of object "b". See the code. I think it's getting clear.
The b.o is a createObject too. A copy constructed from a (on line 21).
Yes, you do use a reference parameter, but that just saves an additional copy.
If the x were by value, you would first copy a to x and then x to o.
The x as reference lets you essentially copy a to o directly.
The result is as expected 10, 12 ,12. But did I what you told me? ;-) Now i don't create a copy of "a" to "o" anymore, but i pass the reference of "a" to "o".