Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No member named 'begin' in namespace 'std'

I successfully compiled on Windows a code that should be crossplatform. Now when compiling it in Xcode with Mac OS X, I get:

std::valarray<float> v(32);
...
std::sort(begin(v), end(v));            # Use of undeclared identifier 'begin'
std::sort(std::begin(v), std::end(v));  # No member named 'begin' in namespace 'std'
std::sort(std::valarray::begin(v), std::valarray::end(v));  # Idem, error as well

Why does the error No member named 'begin' in namespace 'std' happen?

like image 592
Basj Avatar asked Oct 05 '16 13:10

Basj


1 Answers

std::begin was introduced with C++11. See this answer for how to enable C++11 in XCode 4.2 (the precise name of the dialect has probably changed by now).

Alternatively, if you can't move to C++11, switch to std::vector and use v.begin().

like image 142
Martin Bonner supports Monica Avatar answered Oct 14 '22 07:10

Martin Bonner supports Monica