Generic Programming
가변인자 템플릿 예제
hellobird
2019. 3. 22. 23:28
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include <iostream> using namespace std; template <typename T, typename ... ARGS> void Goo (T a, ARGS ... args) { static int n = 0; ++n; cout << n << ": " << typeid(T).name() << " : " << a << endl; // 꺼낼 때는 'recursive'한 방법으로 꺼내야 한다. // recursive한 방식으로 동작하므로 작은 코드에 대해서만 사용해야한다. Goo(args...); } // 재귀의 종료를 위해 인자없는 Goo 함수가 필요하다. void Goo () { cout << "Goo 종료" << endl; } int main(int argc, char* argv[]) { Goo(1, 3.4, "aa", 5); return 0; } | cs |