0

I need to have a uniq map object to store key-vlaue globally. So I created a class with a static unordered_map as the member, my code as following please:

class PopMap {
    public:
        static unordered_map<string, string> dataMap;
        PopMap(){};
        ~PopMap(){};
};
int main(){
    PopMap::dataMap["name"]="Tom";
    return 0;
} 

But I got the following exception: undefined reference to PopMap::dataMap

Jack
  • 5,540
  • 13
  • 65
  • 113
  • 2
    https://en.cppreference.com/w/cpp/language/static: "The declaration inside the class body is not a definition". So you need a definition `unordered_map PopMap::dataMap;` at top level. Example: https://godbolt.org/z/WeTssP – Nate Eldredge Nov 30 '20 at 03:16
  • See https://stackoverflow.com/questions/272900/undefined-reference-to-static-class-member/272965#272965 – Drew Hall Nov 30 '20 at 03:22

0 Answers0