example2_recursive_variadic_function.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <iostream>

// Base case: No arguments left
void print() {
    std::cout << "End of arguments" << std::endl;
}

// Recursive case: Process one argument and recurse
template<typename T, typename... Args>
void print(T first, Args... args) {
    std::cout << first << std::endl;  // Print the first argument
    print(args...);  // Recursively call print with the remaining arguments
}

int main() {
    print(1, 2.5, "Hello", 'A');
    return 0;
}
Back to variadic_template