爲什麼我收到鏈接錯誤,當我嘗試在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);
}
錯誤是:
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 ,int> > > MyClass::_myMap" ([email protected]@@[email protected][email protected]@[email protected]@[email protected][email protected][email protected]@@@[email protected]@[email protected]@A) test22.obj test22
本質上是[靜態結構鏈接器錯誤](http://stackoverflow.com/questions/1850809/static-struct-linker-error)等的重複。 – Troubadour 2010-08-27 14:27:42
[定義靜態成員在C++中]的可能的重複(http://stackoverflow.com/questions/3536372/defining-static-members-in-c) – 2012-09-25 03:57:33