Hacker News new | ask | show | jobs
by codeofthedamned 3823 days ago
I have corrected the code by removing the reference.

The way the code is now structured will allow for the RVO (Return-value optimization) to occur, so the new instance will be constructed in the location of the receiving object.

Move semantics would not apply in this case, it would actually suffer from a similar problem as the version that returned a reference, except the program would not crash. Instead the return value would contain garbage.

(edit: added a link to details on how to use move semantics) http://codeofthedamned.com/index.php/c-r-value-references

I did not use expression templates, or try to optimize any of the implementation because my intent is to demonstrate "how" to get started with the math. I also wanted to make the code accessible to programmers that do not use C++. For example, someone trying to learn WebGL.