Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My understanding is simply that many programmers have a habit of passing parameters as const references. If they want a copy of the parameter, they make that copy by hand. In fact, on Thursday, I found a function in the code I work on that does exactly this.

That prevents some compiler optimizations ( http://stlab.adobe.com/wiki/images/8/85/2008_06_26_classes_t... ), but those optimizations predate C++11, so I don't know why the advice is in this article. In any case, if you want a function to operate in a copy of a parameter, consider passing that parameter by value instead of passing it by const reference and then making a copy. Note, this is not advice to start making unnecessary copies; instead it's advice that if you need a copy of something, rely on the compiler to make that copy for you.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: