By default, C++ passes objects to and from functions by value. Unless you specify otherwise, function parameters are initialized with copies of the actual arguments, and function callers get back a copy of the value returned by the function. These copies are produced by the objects’ copy constructors. This can make pass-by-value an expensive operation. If you use pass-by-reference-to-const instead of pass-by-value, it will save the overhead of making unnecessary copies.
Passing parameters by reference also avoids the slicing problem. When a derived class object is passed(by value) as a base class object, the base class copy constructor is called, and the specialized features that make the object behave like a derived class object are “sliced” off. This is almost never what you want. For example
1 | class Window |