|
|
Rather than have a large object pushed onto the stack, you
can pass a reference to the object. If you want to indicate
that the function won't be making any changes to the object,
you can pass it by const reference. This is probably the
most common use of references, since it acts like an
"efficient call by value:''
void print_large_array( const int& ar[], int n )
or
void print_large_array( const int* &ar, int n )
The above two are equivalent.
A class acts like a struct that is passed implicitly to all its
member functions. You can indicate that a member function
does not modify the data area of its class by using const,
giving the same "efficient call by value'' for the implicit
class argument that the previous section gave to explicit
arguments:
|
|