6.3. Handling Template Type Parameters
Handling a template type parameter is somewhat more complicated than handling an explicit parameter type. For example, to declare an explicit int parameter to a function, we write
bool find( int val );
passing it by value. However, to declare an explicit Matrix class parameter to a function, we instead write
bool find( const Matrix &val );
passing it by reference in order not to generate an unnecessary copy of the Matrix class object. Our program is not wrong if we declare find() as follows:
// not wrong, but inefficient bool find( Matrix val );
It simply takes longer to reach the same conclusion and is likely to be criticized by readers of our code, particularly if find() is called frequently within ...
Get Essential C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.