My Blog

My WordPress Blog

My Blog

My WordPress Blog

Function Templates with Multiple Parameters

This example shows how to define a function template that works with multiple parameters.

cppCopy code#include <iostream>

template <typename T1, typename T2>
void displayPair(T1 first, T2 second) {
std::cout &lt;&lt; "First: " &lt;&lt; first &lt;&lt; ", Second: " &lt;&lt; second &lt;&lt; std::endl;
} int main() {
displayPair(42, "Hello");          // Output: First: 42, Second: Hello
displayPair(3.14, 100);            // Output: First: 3.14, Second: 100
return 0;
}
Function Templates with Multiple Parameters

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top