Weird linker error with static std::map

前端 未结 1 1181
逝去的感伤
逝去的感伤 2021-01-07 16:55

Why do I get linker error when I try to compile this in Visual Studio 2008

#include 
#include 
#include 
#include          


        
1条回答
  •  时光取名叫无心
    2021-01-07 17:37

    You've declared the static member _myMap, but not defined it. Add this line just above int main():

    std::map MyClass::_myMap;
    

    Think of it like a function that has been declared but not defined in any .cpp file - you get a linker error if you use it.

    0 讨论(0)
提交回复
热议问题