Hi,
Regarding the following snippet I know that we are dealing with freind functions, members, classes etc., but I need help in identifying what "this" is:
(from below)
this structure is?
1 2 3 4
void displayItem(Storage &storage)
{
....this is ??
}
A reference to an object is the parameter there.
It will avoid invoking a copy constructor and any changes made to it inside that function will alter the original object.
Edit: Addition. Passing by reference is preferred to passing by value, especially for large objects. If you do not need to modify the object, you can pass it as a const reference, ie void displayItem(const Storage &storage)
In the pass by reference-to-const and pass by pointer-to-const cases, any attempts to change the caller’s [members] within the function would be flagged by the compiler as an error at compile-time. This check is done entirely at compile-time: there is no run-time space or speed cost for the const
But as an added caveat, any functions you use that object with in that function must also be const qualified, including the object's own member functions. https://isocpp.org/wiki/faq/const-correctness