input_iterator询问模板名称
input_iterator asking for a template name
我一直在尝试编译下面的代码,但显示错误。我不确定它期望什么模板名称。我是新手,这是一个非常旧的代码,正在新的g ++编译器上进行编译。谁能帮忙?
提前感谢,欣赏它。
错误:
./dir.h:12: error: expected template-name before â<â token
./dir.h:12: error: expected â{â before â<â token
./dir.h:12: error: expected unqualified-id before â<â token
make: *** exit code 1 making Life.o
法典:
#if !defined(DIRECTORY_H)
#define DIRECTORY_H
#include <string>
#include <algorithm>
#include <iterator>
//using std::input_iterator;
using std::string;
struct dir_it_rep;
class dir_it : public input_iterator<string,int> //<------- Line 12
{
public:
dir_it(); // "past the end" ctor
explicit dir_it(string const &); // the "normal" ctor
dir_it(dir_it const &it);
~dir_it();
dir_it &operator= (dir_it const &it);
string operator* () const { return i_value; }
dir_it &operator++ ();
dir_it operator++ (int) { dir_it rc (*this); operator++(); return rc; }
bool operator== (dir_it const &it) const;
bool operator!= (dir_it const &it) const { return !operator== (it); }
private:
dir_it_rep *i_rep; // representation for the next value
string i_value; // the current value
};
#endif /* DIRECTORY_H */
第一:没有std::input_iterator
。第二:迭代器是通过概念而不是通过类层次结构来分配的。
标准库提供了基类std::iterator
,为迭代器提供通用的兼容接口(换句话说,为了简化事情)。但是不同类型的迭代器只是您自己的迭代器实现必须满足的概念才能属于特定的迭代器类别。
换句话说:不同的迭代器类别(前向迭代器、输入迭代器、双向迭代器)只是类概念。也就是说,例如,如果要编写一个要被视为前向迭代器的类,则类必须满足条件/功能列表:
-
您的类必须是默认可构造的。
-
您的类也必须满足输入迭代器概念。
-
必须重载满足一组指定行为的前增量和后增量运算符(阅读文档)。
-
该类必须是可取消引用的,即重载
operator*()
。
以下是解释ForwardIterator
概念要求的文档。
此外,标准库提供了一组类,这些类充当"标签"来确定迭代器类的类别(因为迭代器不是类层次结构,我们需要一个间接形式来确定迭代器的类别。请注意,在常见情况下,这并不令人担忧,因为我们以通用方式使用迭代器): http://en.cppreference.com/w/cpp/iterator/iterator_tags
阅读有关迭代器库的文档。它提供了关于迭代器、其分配和概念的良好解释。
相关文章:
- "input.length();"的目的是什么?
- 如何使用"derived input class"创建派生类?
- 在调试模式下引发C++ "deque iterator not dereferencable"异常
- std::iterator::reference 必须是引用吗?
- 为什么unordered_set<string::iterator>不起作用?
- 造成致命错误:boost/fusion/iterator/equal_to.hpp 没有这样的文件或目录
- Visual accept std::string from std::byte iterator
- 开放CV垫"Sizes of input arguments do not match"的问题
- 什么是"std::set<int,int>::iterator"?
- 从 std::vector 中删除项目时"Iterator not incrementable"
- 如何从 boost::container::vector<std::string>::iterator 访问索引和对象?
- 什么是"Reading unbounded stream from standard input (Memory Management)"的例子
- 如何检查输入是否为字符并显示它是"invalid input",否则它将按原样运行
- 空集"Out of bound iterator"
- 输出 [left]=input[i] 行中的 c++ 代码中存在无效的类型错误
- 无法在"surface input"模式下使用 Android 平台的 MediaCodec 类
- 如何使用set<pair<int,int> >::iterator itrator it迭代set<pair<int,int> >st中的值?
- CMD:程序.exe 1< "A:/input.txt"产生无输出
- 给定一个类型为 Container:<T>:Iterator 的函数参数,如何为某些类型的 T 实现特定的重载?
- mmap with /dev/input/event*