This error is driving me crazy.
I have reproduced the error in the simplified example below.
The last code tag contains the same example in one file, and it works.
So there is something about the way the code is broken up into more files and linked that is causing the error.
#include "map.h"
// initialize static map out of class
// map must be compiled with: g++ -std=c++11 fileName.cpp
A::KeyMap A::km = {{1, 'a'}, {2, 'b'}};
int main()
{
A a(1);
std::cout << a.getChar(); // should print 'a'
}
D:\wolf\Documents\teensy\demo_MinGW\map_link>make
g++ main.cpp map.o -o a.exe
main.cpp:4:38: error: in C++98 'A::km' must be initialized by constructor, not b
y '{...}'
A::KeyMap A::km = {{1, 'a'}, {2, 'b'}}; // compiles w/o const
^
main.cpp:4:38: warning: extended initializer lists only available with -std=c++1
1 or -std=gnu++11 [enabled by default]
main.cpp:4:38: error: could not convert '{{1, 'a'}, {2, 'b'}}' from '<brace-encl
osed initializer list>' to 'A::KeyMap {aka std::map<const int, const char>}'
make: *** [a.exe] Error 1
When the same code is in one file it works fine:
map.cpp:
Which translated into: g++ main.cpp map.o -o a.exe
main.o was never being created, thus it never got the -std=c++11 flag.
You might have noticed this if your "clean" was a more upfront:
1 2
clean:
rm main.o map.o
When running clean, you would have got an error message about main.o not existing.
[quote]You shouldn't need map.h as a prerequisite for your rule to build map.o[/code]
You don't need it, but you want it. You also want it to be a prerequisite for main.o.