프로그래밍(Programming)/c++, 11, 14 , 17, 20
첫번째 가변인자로 오버로딩 처리
3DMP
2021. 6. 22. 18:05
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include <iostream>
using namespace std;
template<typename T>
T f(T a)
{
return a + 1;
}
class A { //f 함수 테스트시 A 를 제외하고 생각하면 된다
public:
};
template <typename ... Types>
void s1(char cc, Types ... args)
{
}
template <typename ... Types>
void s1(int cc, Types ... args)
{
}
template <typename ... Types>
void s1(A cc, Types ... args)
{
}
template <typename ... Types>
void foo(Types ... args) //받는건 가변인자로 다 받는데
{
s1(args...); //인자 첫번째 타입에 따라 s1 함수가 호출 된다
//s1(f(args)...); //개별 인자들에 +1 을 다 한다음 기반 parameter pack 을 넘긴다
}
int main(int argc, char* argv[])
{
foo('s', A(), 3);
foo(A(), 's', 3);
foo(1, 2.0f, 3);
return 0;
}
|
cs |
반응형