Perché ricevo errore di linker quando provo a compilare questo in Visual Studio 2008errore del linker strano con std :: statica mappa
#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);
}
errore è:
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
Sostanzialmente un duplicato di [Errore statico del linker struct] (http://stackoverflow.com/questions/1850809/static-struct-linker-error) tra gli altri. – Troubadour
possibile duplicato di [Definizione di membri statici in C++] (http://stackoverflow.com/questions/3536372/defining-static-members-in-c) –