我有这样的功能:如何使用模板中的参数调用模板化函数?
template <typename T, T sep>
void split(){
std::cout << sep << std::endl;
}
当我尝试用这个命令来调用它:split<'f'>();
我得到以下错误:
q3.cpp: In function ‘int main()’:
q3.cpp:36:16: error: no matching function for call to ‘split()’
split<'f'>();
^
q3.cpp:36:16: note: candidate is:
q3.cpp:31:6: note: template<class T, T sep> void split()
void split(){
^
q3.cpp:31:6: note: template argument deduction/substitution failed:
为什么?
将分隔符作为模板参数而不是函数参数的目的是什么?为什么不'template void split(T const&sep){...}'? –
@Someprogrammerdude学习目的 – TheLogicGuy