简体   繁体   English

如何在STLport库中使用const auto

[英]How to use const auto with STLport library

I've tried to compile elementary example: 我尝试编译基本示例:

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

And I've received error: 而且我收到了错误:
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>'

Does STLport support const auto ? STLport支持const auto吗?

EDIT: I'm using GCC 4.6 编辑:我正在使用GCC 4.6
With 4.7 and more everything is ok. 使用4.7及更高版本,一切正常。

gcc 4.6 came out in the spring of 2011, was not without bugs in most C++11 features. gcc 4.6于2011年春季发布,它在大多数C ++ 11功能中都存在错误。 Moroever, around the same time the rules for ADL lookup in range-for were also modified (note that this was prior to the official ratification of the C++11 Standard in the summer of 2011). Moroever,大约在同一时间,range-for中的ADL查找规则也进行了修改(请注意,这是在2011年夏季正式批准C ++ 11标准之前)。 See this Q&A for more details. 有关更多详细信息,请参见此问答 It's probably not worth debugging this and the recommended course of action is to upgrade to a recent version of gcc (4.7 or preferably 4.8). 可能不值得调试,建议的操作步骤是升级到最新版本的gcc(4.7或4.8)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM