매개 변수 팩이 가변 매개 변수 함수에서 마지막 매개 변수가 아닌 경우 어떻게 작동하는지 이해하려고합니다. 내 샘플 코드에서 일부 호출이 작동하지 않는 이유는 모르겠다. 질문은 코멘트에 있습니다. 그들은 작동해야합니까 또는 뭔가를 이해하지 못하거나 VS2015 업데이트 3의 컴파일러가 아직 그들을 지원하지 않습니다? 함수 템플릿, 매개 변수 팩의 종류가에서의 경우에만 추론 할 수 있기 때문에마지막 매개 변수 팩 컴파일 오류
template <typename T>
double sum(T t) {
return t;
}
template <typename T, typename... Rest>
double sum(Rest... rest, T t) {
return t + sum(rest...);
}
template <typename T>
double sum2(T t) {
return t;
}
template <typename T, typename... Rest>
double sum2(T t, Rest... rest) {
return t + sum2(rest...);
}
template<typename... Args>
void func(Args..., int = 0)
{}
void func()
{
func<int, int, int>(1, 1, 1);
func(1, 1, 1); // why doesn't this compile?
sum(1, 1); // why doesn't this compile?
sum<int, int>(1, 1);
sum<int, int, int>(1, 1, 1); // why doesn't this compile while func<int, int, int>(1, 1, 1) does?
// why are these compile? I only changed the order of the parameters compared to sum()
sum2(1);
sum2(1, 1);
sum2(1, 1, 1);
}