Registered Member
|
I am having troubles finding out why a piece of code doesn't work as I'm expecting.
Consider the following M(N)WE:
The output should be the same for both functions (f(b) = g(b)). However I get two different results. Automatic return type deduction should deduce the return type of $f$ to be some vector expression. However, when assigning to v, the copy constructor should be called correctly. There is no aliasing issue here. I cannot figure out where/why the program breaks. Any ideas? PS: compiled with gcc c++11 |
Moderator
|
The function g is invalid because cross returns a temporary which is then referenced by the addition expression returned by g, but this reference becomes invalid after the function returned.
|
Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot]