¿Por qué recibo el error enlazador cuando intento compilar esto en Visual Studio 2008error de vinculador extraño con std :: mapa estático
#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 es:
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
Esencialmente un duplicado de [Static struct linker error] (http://stackoverflow.com/questions/1850809/static-struct-linker-error) entre otros. – Troubadour
posible duplicado de [Definición de miembros estáticos en C++] (http://stackoverflow.com/questions/3536372/defining-static-members-in-c) –