【问题标题】:using the `auto` keyword with STL iterators使用带有 STL 迭代器的 `auto` 关键字
【发布时间】:2018-09-27 02:47:28
【问题描述】:

我正在关注 this 教程,了解如何将 auto 关键字与 STL 迭代器一起使用。

它说这种语法对于 C++ 11 来说是可以的。

vector<int> vec;
auto itr = vec.iterator(); // instead of vector<int>::iterator itr

但是,我在尝试时收到此编译错误?

错误:“std::vector::iterator”的使用无效

【问题讨论】:

  • 该教程中有很多错误。我建议不要读它。

标签: c++ c++11 stl iterator auto


【解决方案1】:

教程错了。 iterator 是所有集合类中的 type 成员,而不是 function 成员。它是vector的一些成员函数的返回类型

教程大概的意思是

vector<int> vec;
auto itr = vec.begin(); // itr is of type std::vector<int>::iterator

【讨论】:

    猜你喜欢
    • 2013-01-11
    • 1970-01-01
    • 2011-03-26
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-10
    • 1970-01-01
    相关资源
    最近更新 更多