我正在尝试将项目放在2维无序地图中,如下所示:
#include <unordered_map>
#include <string>
#include <vector>
class Scene {
protected:
static std::unordered_map<std::string, std::unordered_map<std::string, Mesh>> Meshes;
public:
static void loadMesh(std::string filename) {
std::string meshName;
std::vector<GLfloat> v;
std::vector<GLfloat> vn;
etc..
Meshes[filename].emplace(std::make_pair(meshName, Mesh(v, vn, vt, f))); // This causes the error
}
}
我也尝试过使用它:
Meshes[filename][meshName] = Mesh(v, vn, vt, f);
但它一直给我这个很长的错误:
Error 2 error LNK2001: unresolved external symbol "protected: static class std::unordered_map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::unordered_map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class Mesh,struct std::hash<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::equal_to<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class Mesh> > >,struct std::hash<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::equal_to<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::unordered_map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class Mesh,struct std::hash<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::equal_to<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class Mesh> > > > > > Scene::Meshes" (?Meshes@Scene@@1V?$unordered_map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$unordered_map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VMesh@@U?$hash@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@U?$equal_to@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VMesh@@@std@@@2@@2@U?$hash@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@U?$equal_to@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$unordered_map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VMesh@@U?$hash@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@U?$equal_to@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VMesh@@@std@@@2@@2@@std@@@2@@std@@A) C:\Users\Gebruiker\Documents\Visual Studio 2013\Projects\C++ Projects\Engine\Engine\Scene.obj
我是以错误的方式使用无序地图,还是我错过了什么?
答案 0 :(得分:2)
您声明了Meshes
,但您没有定义它。添加这样的一行
std::unordered_map<std::string, std::unordered_map<std::string, Mesh>> Scene::Meshes;
到一个(也是唯一一个).cpp文件。