I was looking up ways to initialize static map in C++ and found this code:
struct A{ static map<int,int> create_map() { map<int,int> m; m[1] = 2; m[3] = 4; m[5] = 6; return m; } static const map<int,int> myMap; }; const map<int,int> A:: myMap = A::create_map(); However, if I change the last line to
const static map<int,int> A:: myMap = A::create_map(); Compiler complaints: 'static' may not be used when defining (as opposed to declaring) a static data member" ?
I wonder why? What's the logic or reasoning behind this ?