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 << "First: " << first << ", Second: " << second << std::endl;
}

int main() {
    displayPair(42, "Hello");          // Output: First: 42, Second: Hello
    displayPair(3.14, 100);            // Output: First: 3.14, Second: 100
    return 0;
}

Comments

Leave a Reply

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