我有一個靜態std :: map成員變量的類,它將char
s映射到自定義類型Terrain
。我試圖在類的實現文件中填充這張地圖,但是我收到了一些錯誤。這是我的頭文件:填充靜態std :: map類成員變量時發生衝突聲明
#ifndef LEVEL_HPP
#define LEVEL_HPP
#include <bitset>
#include <list>
#include <map>
#include <string>
#include <vector>
#include "libtcod.hpp"
namespace yarl
{
namespace level
{
class Terrain
{
// Member Variables
private:
std::bitset<5> flags;
// Member Functions
public:
explicit Terrain(const std::string& flg)
: flags(flg) {}
(...)
};
class Level
{
private:
static std::map<char, Terrain> terrainTypes;
(...)
};
}
}
#endif
,這裏是我的執行文件:
#include <bitset>
#include <list>
#include <map>
#include <string>
#include <vector>
#include "Level.hpp"
#include "libtcod.hpp"
using namespace std;
namespace yarl
{
namespace level
{
/* fill Level::terrainTypes */
map<char,Terrain> Level::terrainTypes['.'] = Terrain("00001"); // clear
map<char,Terrain> Level::terrainTypes[','] = Terrain("00001"); // clear
map<char,Terrain> Level::terrainTypes['\''] = Terrain("00001"); // clear
map<char,Terrain> Level::terrainTypes['`'] = Terrain("00001"); // clear
map<char,Terrain> Level::terrainTypes[178] = Terrain("11111"); // wall
(...)
}
}
我用g ++以及我得到的錯誤是
的src/Level.cpp:15:錯誤:衝突聲明'std :: map,std :: allocator>> yarl :: level :: Level :: terrainTypes [46]'
src/Level.hpp:104:error:'yarl :: level :: Level: :terrainTypes'以前的聲明爲'std :: map,std :: allocator>> yarl :: level :: Level :: terrainTypes'
src/Level.cpp:15:錯誤:聲明std :: map,std :: allocator> yarl :: level :: Level :: terrainTypes'class of outside is not definition
src/Level.cpp :15:錯誤:從'yarl :: level :: Terrain'轉換爲非標量類型'std :: map,std :: allocator>''請求
src/Level.cpp:15:error:'yarl: :level :: Level :: terrainTypes'在聲明時不能用非常量表達式初始化
我在實現文件中爲每個映射賦值行獲取一組這些值。任何人看到我做錯了什麼?謝謝你的幫助。
第一個選項解決了這一問題。謝謝你的幫助。 – Max 2010-05-28 20:47:47