Exam 11: Using Templates
Where in your program can you place function templates? Do any restrictions apply?
You can place function templates at the start of a program file, in the global area above the main() function.Alternatively, you can place them in a separate file, and include that file in your program with an #include statement. In either case, the definition of the class template (the statement that contains the word template and the angle brackets holding the class name) and the function template itself must reside in the same source file.When you create a function template, you can't place the template definition and the function code in separate files because the function can't be compiled into object format without knowing the types, and the function won't "know" that it needs to recognize the types without the template definition.,
What happens when you call a function template?
When you call a function template, the compiler determines the type of the actual argument passed to the function. The compiler substitutes the argument type for the generic type in the function template, creating a generated function that uses the appropriate type. The designation of the parameterized type is implicit; that is, it is determined not by naming the type, but by the compiler's ability to determine the argument type.The compiler generates code for as many different functions as it needs, depending on the function calls that are made.,
FIFO stands for ____________________.
first in first out,first in, first out
When you create a(n) ____, you create a list of same-type objects at adjacent memory locations.
The terms template function and ____ are often used interchangeably.
The function call ____ specifies that someFunction 's parameterized type (for example, T ) will be char , no matter what type someArgument is.
When is explicitly specifying a type for the parameterized type useful?
A(n) ____ is one that can stand for any number of C++ types.
The subscript for any array can hold a value of 0 through ____.
A(n) ____ is a template class that has been written to perform common class tasks.
To create a function template that employs multiple generic types, you simply use a(n) ____ for each type.
You can overload function templates only when each version of the function takes a different parameter list.
The purpose of container classes is to manage groups of other classes.
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)