Deck 14: Templates

Full screen (f)
exit full mode
Question
Function templates:

A) Can include objects of template classes as parameters.
B) Must have return type T.
C) Do not need a separate template< typename type > statement if they take objects from a template class as a parameter.
D) Do not need a separate template< typename type > statement.
Use Space or
up arrow
down arrow
to flip the card.
Question
Function-template specializations:

A) Are identical to macros.
B) Are generated at compile time.
C) Have a maximum allowed number of type parameters.
D) Are not more concise than the equivalent set of overloaded functions.
Question
Nontype parameters are:

A) Unable to have default arguments.
B) Specified before the angle-bracket-enclosed type-parameter list.
C) const.
D) Required for class templates.
Question
Which of the following is false?

A) With a non-template class, one copy of a static data member is shared among all objects created from that class.
B) Each class-template specialization created from a class template has its own copy of each static data member.
C) static data members of both template and non-template classes are initialized at file scope.
D) One copy of each static member function is shared between all class-template specializations in the class template.
Question
A difference between function-template specializations and overloaded functions is that:

A) Function-template specializations are generated by the compiler, not the programmer.
B) Function-template specializations cannot accept user-defined types.
C) Function-template specializations do not perform identical operations on each data type.
D) Overloaded functions usually do not perform similar operations on each data type.
Question
Select the incorrect statement.

A) A class-template specialization can be used to derive a class template.
B) A class template can be derived from a nontemplate class.
C) A non-template class can be used to derive a class-template specialization.
D) A non-template class can be derived from a class template-specialization.
Question
Friendship cannot be declared between a class template and:

A) A class-template specialization.
B) A member function of another class.
C) Another class template.
D) A global function.
Question
For a class template, the binary scope resolution operator ::) is needed:

A) Only in the definitions of the member functions defined outside the class.
B) Both in the prototype and definition of a member function.
C) Only if multiple class-template specializations will be created from this class template.
D) In neither the definition nor prototype of member functions.
Question
A function template can be overloaded by:

A) Using other function templates with the same function name and parameters.
B) Using non-template functions with the same name and different parameters.
C) Using non-template functions with a different name but the same parameters.
D) Using other function templates with a different name but the same parameters.
Question
The relationship between function templates and function-template specializations is most similar to the relationship between:

A) Classes and objects.
B) Classes and functions.
C) Functions and return types.
D) Headers and source files.
Question
Assuming that all four of the following functions are defined, which one will be called by the function call square 23.4 )?

A) template< typename T > T square T num )
B) template< typename T1, typename T2 > T1 square T1 num1, T2 num2 )
C) int square int num )
D) double square double num )
Question
Class templates:

A) May include the statement template< typename Type > anywhere.
B) Must put template< typename Type > before the class definition.
C) Must include template< typename Type > inside the class definition.
D) Have the option of including the optional statement template< typename Type >.
Question
Default type parameters are allowed only:

A) If the class template also has nontype parameters.
B) If the class template does not have any nontype parameters.
C) If the class is used as a container class.
D) As the rightmost trailing) parameters in a template's type-parameter list.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/13
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 14: Templates
1
Function templates:

A) Can include objects of template classes as parameters.
B) Must have return type T.
C) Do not need a separate template< typename type > statement if they take objects from a template class as a parameter.
D) Do not need a separate template< typename type > statement.
A
2
Function-template specializations:

A) Are identical to macros.
B) Are generated at compile time.
C) Have a maximum allowed number of type parameters.
D) Are not more concise than the equivalent set of overloaded functions.
B
3
Nontype parameters are:

A) Unable to have default arguments.
B) Specified before the angle-bracket-enclosed type-parameter list.
C) const.
D) Required for class templates.
C
4
Which of the following is false?

A) With a non-template class, one copy of a static data member is shared among all objects created from that class.
B) Each class-template specialization created from a class template has its own copy of each static data member.
C) static data members of both template and non-template classes are initialized at file scope.
D) One copy of each static member function is shared between all class-template specializations in the class template.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
5
A difference between function-template specializations and overloaded functions is that:

A) Function-template specializations are generated by the compiler, not the programmer.
B) Function-template specializations cannot accept user-defined types.
C) Function-template specializations do not perform identical operations on each data type.
D) Overloaded functions usually do not perform similar operations on each data type.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
6
Select the incorrect statement.

A) A class-template specialization can be used to derive a class template.
B) A class template can be derived from a nontemplate class.
C) A non-template class can be used to derive a class-template specialization.
D) A non-template class can be derived from a class template-specialization.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
7
Friendship cannot be declared between a class template and:

A) A class-template specialization.
B) A member function of another class.
C) Another class template.
D) A global function.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
8
For a class template, the binary scope resolution operator ::) is needed:

A) Only in the definitions of the member functions defined outside the class.
B) Both in the prototype and definition of a member function.
C) Only if multiple class-template specializations will be created from this class template.
D) In neither the definition nor prototype of member functions.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
9
A function template can be overloaded by:

A) Using other function templates with the same function name and parameters.
B) Using non-template functions with the same name and different parameters.
C) Using non-template functions with a different name but the same parameters.
D) Using other function templates with a different name but the same parameters.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
10
The relationship between function templates and function-template specializations is most similar to the relationship between:

A) Classes and objects.
B) Classes and functions.
C) Functions and return types.
D) Headers and source files.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
11
Assuming that all four of the following functions are defined, which one will be called by the function call square 23.4 )?

A) template< typename T > T square T num )
B) template< typename T1, typename T2 > T1 square T1 num1, T2 num2 )
C) int square int num )
D) double square double num )
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
12
Class templates:

A) May include the statement template< typename Type > anywhere.
B) Must put template< typename Type > before the class definition.
C) Must include template< typename Type > inside the class definition.
D) Have the option of including the optional statement template< typename Type >.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
13
Default type parameters are allowed only:

A) If the class template also has nontype parameters.
B) If the class template does not have any nontype parameters.
C) If the class is used as a container class.
D) As the rightmost trailing) parameters in a template's type-parameter list.
Unlock Deck
Unlock for access to all 13 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 13 flashcards in this deck.