0
            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’

AFAICSi是一个常量结构internal_file_entry其头代码位于开源 libtorrent 项目中。我只是第一次看 C++,但我一生都无法弄清楚为什么上述调用在编译时失败?i.filename()

4

1 回答 1

5

i是一个指向 an 的迭代器internal_file_entry- 它必须被取消引用。filename像这样访问:

i->filename

这相当于:

(*i).filename
于 2013-03-25T00:03:51.143 回答