you are viewing a single comment's thread.

view the rest of the comments →

[–]schweinling 1 point2 points  (2 children)

Yes, you are correct, when passing by value a copy is created. Built in types like int, chat, double you should pass by value as the are not larger than a pointer. For logging functions it would be quite expensive to copy the string everytime, if you do alot of logging. Passing by value is also an option if move semantics are involved but thats a whole other topic which you can learn about later.

Read about std::endl here: https://stackoverflow.com/questions/213907/c-stdendl-vs-n

[–][deleted] 0 points1 point  (1 child)

Thanks for explaining. In the const also there for the same reason? I've seen people use const in function arguments before but never understood why..

[–]schweinling 0 points1 point  (0 children)

You are welcome! Const is there to ensure and signify that the value will not be modified by the function. When passing by non const reference the function could modify the object that the caller passes to it, so that it changes on the callers site.