我正在浏览一段代码
template <class RAIter>
void alg(RAIter, RAIter, std::random_access_iterator_tag)
{
std::cout << "alg() called for random-access iterator\n";
}
我第一次只看到函数参数部分 (std::random_access_iterator_tag) 中的数据类型。看惯了
[std::random_access_iterator_tag rand_iter;]
这种表示在模板中是允许的,但在非模板函数中是不允许的。
两个问题:
1)为什么只提到了数据类型名称而没有提到它的变量?
2) 为什么只允许模板化函数而不允许非模板化函数?
最佳答案
1) Why is only data type name mentioned but no variable of it is mentioned?
因为没有使用参数,所以不需要名字。
2) Why is it allowed only for templated functions but not for non-templated functions?
实际上 也允许在非模板函数上使用。
关于c++ - 查询 C++ 迭代器标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31883694/