C++11?

I was trying to compile some code with lambda functions using TDM-GCC and everytime I compile: 'g++ -std=c++11 hw8.cpp -o hw8.exe'

the compiler slaps me with:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
c:\Users\admin\Documents\sublimecmd>g++ -std=c++11 hw8.cpp -o hw8.exe
In file included from C:/TDM-GCC-32/lib/gcc/mingw32/5.1.0/include/c++/algorithm:
62:0,
                 from hw8.cpp:8:
C:/TDM-GCC-32/lib/gcc/mingw32/5.1.0/include/c++/bits/stl_algo.h: In instantiatio
n of '_Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter = std::istream_i
terator<std::__cxx11::basic_string<char> >; _Funct = main()::<lambda(std::__cxx1
1::string&)>]':
hw8.cpp:18:92:   required from here
C:/TDM-GCC-32/lib/gcc/mingw32/5.1.0/include/c++/bits/stl_algo.h:3767:5: error: n
o match for call to '(main()::<lambda(std::__cxx11::string&)>) (const std::__cxx
11::basic_string<char>&)'
  __f(*__first);
     ^
hw8.cpp:18:82: note: candidate: main()::<lambda(std::__cxx11::string&)> <near ma
tch>
  for_each(istream_iterator<string>(in), istream_iterator<string>(),[&](string &
 s){m[s]++;});

  ^
hw8.cpp:18:82: note:   conversion of argument 1 would be ill-formed:
In file included from C:/TDM-GCC-32/lib/gcc/mingw32/5.1.0/include/c++/algorithm:
62:0,
                 from hw8.cpp:8:
C:/TDM-GCC-32/lib/gcc/mingw32/5.1.0/include/c++/bits/stl_algo.h:3767:5: error: b
inding 'const std::__cxx11::basic_string<char>' to reference of type 'std::__cxx
11::string& {aka std::__cxx11::basic_string<char>&}' discards qualifiers
  __f(*__first);


what does this even mean? Am I supposed to "enable" c++11? I thought it should already be the standard compiler version by default, considering I only installed TDM-GCC 2 or 3 months ago.
The lambda parameter has to be const.

 
[&](const string & s){m[s]++;}

I think you still have to enable C++11 even in the latest versions of GCC. The problem if they changed this is that it would break a lot of people's build scripts because C++11 is not completely backward compatible with earlier standards.
Last edited on
alright it compiles now, but yeah it seems you have to enable c++11 in order for it to do so
Topic archived. No new replies allowed.