Answers for "Function Template with multiple parameters"

C++
0

Function Template with multiple parameters

#include <iostream>
using namespace std;

template <class TFirst, class TSecond>

//returns smaller number
TFirst smaller(TFirst A, TSecond B) {

	return (A<B?A:B); //if A is less then B then return A; if not, return B
}

int main() {

	int x = 58;
	double y = 56.78;


	std::cout << smaller(x, y) << endl; //TFisrt = int, TSecond = double
	std::cout << smaller(y, x) << endl; //TFisrt = double, TSecond = int
}
Posted by: Guest on May-09-2021

Code answers related to "Function Template with multiple parameters"

Browse Popular Code Answers by Language