A
Arv
After writing code in Java for sometime, one thing that I am not
comfortable at all with C++ is the return type of an object.
In java, i do not remember ever seeing a method return a final
reference -- though a const is not equivalent to final, it is
confusing when i see some methods returning a const reference.
I initially assumed returning an object is same as returning a
reference, because when i call the method as
Myclass O1;
O1 = func();
Does it matter if func() returns a reference, const reference or a
Object, anyways the assignment operator is going to get called.
But I am a bit confused when I call AnotherFunc(func())... so is it
possible that if I dont pass a const reference, and the AnotherFunc
accepts a reference, it can potentially change the object I pass.!
Especially this is more confusing in a getter method, should a getter
return a const reference always, because I do not want ppl to modify
the reference they get by calling a getter.
Sorry if this is a bit basic, but I have not been able to understand
this very clearly...
Thanks
Arv
comfortable at all with C++ is the return type of an object.
In java, i do not remember ever seeing a method return a final
reference -- though a const is not equivalent to final, it is
confusing when i see some methods returning a const reference.
I initially assumed returning an object is same as returning a
reference, because when i call the method as
Myclass O1;
O1 = func();
Does it matter if func() returns a reference, const reference or a
Object, anyways the assignment operator is going to get called.
But I am a bit confused when I call AnotherFunc(func())... so is it
possible that if I dont pass a const reference, and the AnotherFunc
accepts a reference, it can potentially change the object I pass.!
Especially this is more confusing in a getter method, should a getter
return a const reference always, because I do not want ppl to modify
the reference they get by calling a getter.
Sorry if this is a bit basic, but I have not been able to understand
this very clearly...
Thanks
Arv