小编Bla*_*Bla的帖子

静态std :: map出现奇怪的链接器错误

当我尝试在Visual Studio 2008中编译时,为什么会出现链接器错误

#include <stdafx.h>
#include <iostream>
#include <map>
#include <string>

class MyClass
{
public:
 MyClass () { };
 virtual ~MyClass() {};

 static std::string niceString (std::map<int, int> mappp) { _myMap = mappp; return "nice string"; };

private:
 static std::map<int, int> getMap ( ) { return _myMap; };

 static std::map<int, int> _myMap;
}; 

int main(){

 std::map<int, int> mappp;

 mappp[1] = 1;

 std::cout << MyClass::niceString(mappp);

}
Run Code Online (Sandbox Code Playgroud)

错误是:

Error 1 error LNK2001: unresolved external symbol "private: static class std::map<int,int,struct std::less<int>,class std::allocator<struct std::pair<int const …
Run Code Online (Sandbox Code Playgroud)

c++ static std map

23
推荐指数
1
解决办法
9953
查看次数

标签 统计

c++ ×1

map ×1

static ×1

std ×1