You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if this is a bug or by design but it's surprising behaviour to me either way.
In mixed mode, if you have a cpp1 function that returns a reference, calling that function from cpp2 will result in a copy of the object.
This behaves semantically differently to if the function returned a pointer as the referenced object is left unmodified.
E.g.
autoexpand_widget() -> void
{
auto w {get_widget()};
w.size += 42;
}
w is a copy of the object returned from get_widget().
I know the fix is to take a the address of the object but is this copying of a referenced object intentional? If so, is there a design rationale I can read somewhere?
BTW, I'm loving the design of the language as a whole. Even starting by writing small examples you can see how the code is much more readable, safer and terser.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm not sure if this is a bug or by design but it's surprising behaviour to me either way.
In mixed mode, if you have a cpp1 function that returns a reference, calling that function from cpp2 will result in a copy of the object.
This behaves semantically differently to if the function returned a pointer as the referenced object is left unmodified.
E.g.
compiles to
w
is a copy of the object returned fromget_widget()
.I know the fix is to take a the address of the object but is this copying of a referenced object intentional? If so, is there a design rationale I can read somewhere?
Thanks!
BTW, I'm loving the design of the language as a whole. Even starting by writing small examples you can see how the code is much more readable, safer and terser.
Beta Was this translation helpful? Give feedback.
All reactions