7-Template Functions

7-Template Functions - / function templates / / / / /...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// function templates // function templates behave similarly to overloading functions // what happens is the data types are replaced by the template // type. So when the only differences between the program logic // of overloaded functions is the the data types, then we can // use templating. // if the difference bewteen the types requires different logic // then we will have to stick with just overloading. #include <iostream> using namespace std; int sum(int first, int second) { return first + second; } double sum(double first, double second) { return first + second; } template < class T > T summation(T first, T second) { return first + second; } template < class Type > Type typing(Type something, Type other) { Type variable = something; cout << "variable will take on the type of " << "the argument that is passed in\n"; } template < class FirstType, class SecondType > FirstType multiTypes(FirstType one, FirstType two, SecondType three) { FirstType returnMe = one + two; cout << three << " " << two << " " << one << endl;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

7-Template Functions - / function templates / / / / /...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online