c++ - 查询 C++ 迭代器标记

标签 c++

我正在浏览一段代码

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/

相关文章:

c++ - 用宏循环

c++ - CRC4 INTERLAKEN和ITU查找表生成

c++ - Cocos2D BezierBy 随时间增加速度

c++ - LONG_MAX Cygwin 的大小

c++ - C程序生成运行时日志

c++ - 将用户名和密码传递给 CryptRetrieveTimeStamp 函数

c++ - 素数C++

c++ - 64 位 C++ Eclipse 正在制作 32 位可执行文件

c++ - 缺少 shared_ref

c++ - 如何使用 C++ 增加 Visual Studio 内部版本号?