Variadic Templates(数量不定的模版参数)事例
#include <iostream>
using namespace std;
void print() {}
template<typename Type, typename... Types>
void print(Type firstArg, Types ...args) {
cout << firstArg << endl;
print(args...);
}
int main() {
print(7.5, "Hello", bitset<8>(255), 42);
}

#include <iostream>
using namespace std;
void print() {}
template<typename Type, typename... Types>
void print(const Type& firstArg, const Types& ...args) {
cout << firstArg << endl;
print(args...);
}
int main() {
print(7.5, "Hello", bitset<8>(255), 42);
}

浙公网安备 33010602011771号