1

我试图编译基本示例:

#include <vector>
int main ()
{
    std::vector<int> testV;
    for (const auto& test : testV) 
    {   }
    return 0;
}

我收到了错误:
test.cpp: In function 'int main()':
test.cpp:5:29: error: 'begin' was not declared in this scope
test.cpp:5:29: error: 'end' was not declared in this scope
test.cpp:5:29: error: unable to deduce 'const auto&' from '<expression error>'

STLport 支持const auto吗?

编辑:我使用GCC 4.6
的是 4.7 及更多版本,一切正常。

4

1 回答 1

2

gcc 4.6 于 2011 年春天问世,在大多数 C++11 功能中并非没有错误。此外,大约在同一时间,range-for 中的 ADL 查找规则也被修改(请注意,这是在 2011 年夏天正式批准 C++11 标准之前)。有关更多详细信息,请参阅此问答。这可能不值得调试,推荐的做法是升级到最新版本的 gcc(4.7 或最好是 4.8)。

于 2013-08-15T11:24:24.937 回答