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);
}
posted @ 2022-05-16 14:14  OXYGEN1  阅读(19)  评论(0)    收藏  举报