Isnt it pretty obviously what happens here? In the line auto objA = objR;
your objA
variable is not deduced to a MyTest&
but to a MyTest
and becomes thus copy constructed from your obj
(as objR
is just a reference to it). You dont see any output as you havent implemented the copy constructer which is therefor automatically provided by the compiler for you.
If you now call
objR = MYtest("refmodified",1);
Your original object is modified (the assignment operator is called), but your copy (objA
) is left untouched.
The other way round if you call
objA = MYtest("automodified",2);
Your copy is modified but your original object is left untouched.
To do what you want to achieve (objA
being a reference to obj
) you have to declare it like this:
auto& objA = objR;