Domanda

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 ?

EDIT: I'm using GCC 4.6
With 4.7 and more everything is ok.

È stato utile?

Soluzione

gcc 4.6 came out in the spring of 2011, was not without bugs in most C++11 features. 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). 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).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top