15.4 COMPARISON BETWEEN CLASS TEMPLATES AND FUNCTION TEMPLATES

We have so far seen examples with declaration like template<class T>.

It had only one parameter T. It is possible to have two arguments in a template declaration. We can declare a template as

    template <class T , class N>

Now we are in a position to compare and contrast the function and class templates.

The rules for function template and class templates differ about the nature of the template arguments.

1. For declaring function templates, all the arguments in template declaration must be generic (class T). The declaration:

template <class T, class N > is perfectly valid, but the declaration

template <class T, int N> is invalid.

2. For class templates there is no such restriction. ...

Get Object Oriented Programming with C++, Second Edition 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.