1
爲什麼在下列情況下無法明確指定d
?明確指定位於模板參數包後的默認模板參數
#include <iostream>
template< typename a, typename b = int, typename ...c, typename d = int >
int
f(a, b, c..., d)
{
return sizeof...(c);
}
int
main()
{
std::cout << f< int, int, int, int/*, char*/ >(1, 2, 3, 4, 'd') << std::endl;
return 0;
}
如果我去掉最後一個模板參數,那麼我期待輸出2
,而是我得到一個硬錯誤:
main.cpp:14:18: error: no matching function for call to 'f'
std::cout << f< int, int, int, int, char >(1, 2, 3, 4, 'd') << std::endl;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:6:1: note: candidate function not viable: requires 6 arguments, but 5 were provided
f(a, b, c..., d)
^
1 error generated.
什麼是否認在這種情況下,規則?
c其餘 –
@DieterLücking我也懷疑這個,但是處理模板參數包和默認參數的規則是什麼? – Orient
爲什麼可變包裝最後結束的另一個原因。 – 101010