Answer the following statements true (T) or false (F)

1. Suppose the swapValues template is instantiated as follows:
```
int x = 2, y =3;
swapValues(x, y);
// use x and y
x = 4; y =5;
swapValues(x, y);
// use x and y
```
The compiler generates code for two copies of the swapValues template.
2. In the template prefix, template the identifier T is called a value parameter.
3. In the template prefix, template the keyword class means that the type parameter T must be of class type.
4. It is possible to have more than one type parameter in a template definition.
5. It is preferable to separate implementation and specification in software. Hence, it is preferable to place a template class definition in a “header” file, the template implementation of the member functions in an implementation file. The implementation should be compiled separately and linked to the application.


1. False
The compiler generates code for one function of every type for which the template is instantiated. There is only one type; hence, there is only one copy of the function generated. The second call invokes the first instantiation.
2. False
The correct term is type parameter.
3. False
C++ permits any type to be used as a type argument in a template instantiation. In fact, the C++ standard permits use of the keyword typename instead of class.
4. True
Most templates require only one type parameter, but template syntax permits more than one type parameter.
5. False
Most C++ compilers require the template class definitions and member function implementations to be in the same file with the application for compilation. There are compiler dependent #pragma commands for some compilers that more or less achieve the result mentioned in the question, but we have found them to be arcane and difficult to use.
It is possible to explicitly instantiate your templates for every use you have and place these in a separate file. With appropriate #pragma commands, this can be separately compiled and linked to your application. There is an issue of code bloat from compilers generating instantiations in every file where a template is instantiated. This method can prevent that problem.

Computer Science & Information Technology

You might also like to view...

To allow the printer to determine whether or not to insert a page break, use the type ____.

A. always B. avoid C. auto D. inherit

Computer Science & Information Technology

A JavaSpaces service provides the __________ operations.

a) read and write b) read, write and remove c) read, write and take d) read, write and put

Computer Science & Information Technology

What is the risk of having platforms use the SQL language?

What will be an ideal response?

Computer Science & Information Technology

The ________ buttons allow the user to navigate to other folders or libraries that have already been opened without closing the current window

A) search box B) Backstage C) views D) Back and Forward

Computer Science & Information Technology