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

Explanation of Solution

Method of writing a function template:

Before starting to write a function template, first create a regular function with proper parameter list and definition. Then, convert the regular function into a function template.

Steps involved for converting a function into a function template:

  • Define a regular function.
  • Test the regular function with sample data and debug the function whether it works properly or not.
  • Once it is executed correctly, then convert into a template by adding template prefix with type parameter.

Example:

For example, consider the following function “multiply” is used to multiply the given values as follow as:

//Regular function

//d...

Blurred answer
Students have asked these similar questions
When does a function template's code get generated by the compiler?
In C++, as an actual parameter, can an array be passed by value?
The differences between value types and reference types applies to parameters. True False

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