templates chp14 algs

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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.

Using non-template functions with the same name and different parameters.

Macros, are

a preprocessor feature in languages like C/C++ that allow you to define an expression or block of code that will be replaced by the compiler before compile time, where the macro is called. Macros are not type-safe and do not provide any error checking, which often can lead to unexpected behavior.

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.

a. Function-template specializations are generated by the compiler, not the programmer.

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. const.

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 )

d. double square( double num )

friendship

enables a class designer to specify nonmember functions that can access a class's non-public members

Templates enable us to specify, with a single code segment, an entire range of related functions called ,_______ or an entire range of related classes called ______.

function-template specializations class-template specializations

The related functions generated from a function template all have the same name, so the compiler uses _______ resolution to invoke the proper function.

overload

Class templates also are called _______types

parameterized

The ________ operator is used with a class-template name to tie each member-function definition to the class template's scope

scope resolution

All function-template definitions begin with the keyword _______, followed by a list of template parameters to the function template enclosed in _______

template angle brackets (< and >)

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.

A non-template class can be used to derive a class-template specialization.

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.

Another class template.

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.

Are generated at compile time.

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.

As the rightmost (trailing) parameters in a template's type-parameter list

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. Do not need a separate template< typename type >statement.

Can include objects of template classes as parameters.

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.

Classes and objects.

T/F Keywords typename and class as used with a template type parameter specifically mean "any user-defined class type."

F Keywords typename and class in this context also allow for a type parameter of a fundamental type.

t/F Template parameter names among template definitions must be unique

False. Template parameter names among function templates need not be unique.

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 >.

Must put template< typename Type > before the class definition

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

One copy of each static member function is shared between all class-template specializations in the class template.

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.

Only in the definitions of the member functions defined outside the class.

T/F A function template can be overloaded by another function template with the same function name.

T

T/F Each member-function definition outside a class template must begin with a template header.

T

T/F The template parameters of a function-template definition are used to specify the types of the arguments to the function, to specify the return type of the function and to declare variables within the function.

T


Ensembles d'études connexes

Module 10: Network Services Quiz

View Set

Exam 2, Chapters 5, 7, 10, and 11

View Set

Chapter 4 SQL Data Types: CHAR & VARCHAR

View Set

Infection- Tuberculosis, Meningitis/ Bioterrorism & Epidemics

View Set

PrepU for Videbeck's Psychiatric-Mental Health Nursing, 7 Edition Chapter 8

View Set