STARTING OUT WITH C++ MPL
STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 16.2, Problem 16.6CP

Explanation of Solution

Function template:

In C++, a function template is referred as a “generic” function, which can work with different data types.

  • While writing a function template, a programmer should use a “type parameter” to denote a “generic” data type instead of using the actual parameter.
  • The compiler generates the code, when it encounters a function call to a function template. This code will handle the particular data type which is used in the function call.
  • The compiler indentifies the argument type and generates the code to work with those types.
  • The generated code is referred as “template function”.

Example:

For example consider the following function template for finding a cube of value:

template <class T>

T cube(T x)

{

return x * x * x ;

}

  • A function template must begin with the keyword “template” and it is followed by a pair of angle brackets, which contains one or more “generic” data types...

Blurred answer
Students have asked these similar questions
In terms of debugging and profiling, what are the challenges associated with function objects, especially when they're nested or chained?
Using C++ Programming language: Assume you want a function which expects as parameters an array of doubles and the size of the array. Write the function header that accepts these parameters but is defined in such a way that the array cannot be modified in the function.  You can use your own variable names for the parameters.
Define the terms function header (or heading), function body, and function definition. **use c++ programming language

Chapter 16 Solutions

STARTING OUT WITH C++ MPL

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT