为什么这段 c++ 找不到结构成员"文件名"?
Why does this piece of c++ not find the struct member 'filename'?
for (torrent_info::file_iterator i = t.begin_files();
i != t.end_files(); ++i, ++index)
{
int first = t.map_file(index, 0, 1).piece;
int last = t.map_file(index, i->size - 1, 1).piece;
std::cout << " " << std::setw(11) << i->size
<< " " << i.filename() << "[ " << first << ", "
<< last << " ]n";
}
编译会产生以下错误:
error: ‘class __gnu_cxx::__normal_iterator<const libtorrent::internal_file_entry*, std::vector<libtorrent::internal_file_entry, std::allocator<libtorrent::internal_file_entry> > >’ has no member named ‘filename’
AFAICS i
是一个常量internal_file_entry
结构体,其头代码位于开源libtorrent项目中。我只是第一次看c++,但是我不会我的生活工作,为什么上面调用i.filename()
在编译时失败?
i
是指向internal_file_entry
的迭代器-必须对其解引用。像这样访问filename
:
i->filename
这相当于:
(*i).filename
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 对RValue对象调用的LValue ref限定成员函数
- 为什么使用 "this" 指针调用派生成员函数?
- 从命令行c++发送文本文件名
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 助记符和指向成员语法的指针
- 用于访问容器<T>数据成员的正确 API
- 内置函数可查看CPP中的成员变量
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 嵌套在类中时无法设置成员数据
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 将函数类成员映射到类本身内部
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 将Ref对象作为类成员
- 将包含C样式数组的对象初始化为成员变量(C++)
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么这段 c++ 找不到结构成员"文件名"?