Deck 18: Introduction to Custom Templates

Full screen (f)
exit full mode
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 T square(T num)
B) template T1 square(T1 num1, T2 num2)
C) int square(int num)
D) double square(double num)
Use Space or
up arrow
down arrow
to flip the card.
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
Function templates:

A) Can include objects of template classes as parameters.
B) Must have return type T.
C) Do not need a separate template statement if they take objects from a template class as a parameter.
D) Do not need a separate template statement.
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.
Question
Which of the following is true?

A) Only class templates may specify default type arguments for type parameters.
B) Only function templates may specify default type arguments for type parameters.
C) As of C++ 11, you can use default type arguments for template type parameters in function templates.
D) None of the above.
Question
Class templates:

A) May include the statement template anywhere.
B) Must put template before the class definition.
C) Must include template inside the class definition.
D) Have the option of including the optional statement template.
Question
Nontype parameters are:

A) Unable to have default arguments.
B) Specified before the angle-bracket-enclosed type-parameter list.
C) Constants.
D) Required for class templates.
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
For a class template, the 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
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/9
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 18: Introduction to Custom Templates
1
Assuming that all four of the following functions are defined, which one will be called by the function call square(23.4)?

A) template T square(T num)
B) template T1 square(T1 num1, T2 num2)
C) int square(int num)
D) double square(double num)
D
2
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.
B
3
Function templates:

A) Can include objects of template classes as parameters.
B) Must have return type T.
C) Do not need a separate template statement if they take objects from a template class as a parameter.
D) Do not need a separate template statement.
A
4
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 9 flashcards in this deck.
Unlock Deck
k this deck
5
Which of the following is true?

A) Only class templates may specify default type arguments for type parameters.
B) Only function templates may specify default type arguments for type parameters.
C) As of C++ 11, you can use default type arguments for template type parameters in function templates.
D) None of the above.
Unlock Deck
Unlock for access to all 9 flashcards in this deck.
Unlock Deck
k this deck
6
Class templates:

A) May include the statement template anywhere.
B) Must put template before the class definition.
C) Must include template inside the class definition.
D) Have the option of including the optional statement template.
Unlock Deck
Unlock for access to all 9 flashcards in this deck.
Unlock Deck
k this deck
7
Nontype parameters are:

A) Unable to have default arguments.
B) Specified before the angle-bracket-enclosed type-parameter list.
C) Constants.
D) Required for class templates.
Unlock Deck
Unlock for access to all 9 flashcards in this deck.
Unlock Deck
k this deck
8
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 9 flashcards in this deck.
Unlock Deck
k this deck
9
For a class template, the 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 9 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 9 flashcards in this deck.