我不确定我应该如何正确地为一个结构的 Map 初始化 .
struct Tile
{
char character;
map<char,Tile*> neighbors;
Tile(char c)
{
character = c;
neighbors = new map<char,Tile*>();
}
};
当我尝试初始化它时,我得到:
错误:'operator ='不匹配(操作数类型是'std :: map'和'std :: map *')
注意:候选人是:| c:\ mingw \ lib \ gcc \ mingw32 \ 4.8.1 \ include \ c \ bits \ stl_map.h | 264 |注意:std :: map <_Key,_Tp,_Compare,_Alloc>&std :: map <_Key, _Tp,Compare, Alloc> :: operator =(const std :: map <_Key,_Tp,_Compare,_Alloc>&)[with _Key = char; _Tp = boardTile *; _Compare = std :: less; _Alloc = std :: allocator>] | c:\ mingw \ lib \ gcc \ mingw32 \ 4.8.1 \ include \ c \ bits \ stl_map.h | 264 |注意:参数1从'std :: map *'到'const std :: map&'没有已知的转换“|
2 回答
这个
不动态分配,所以丢弃这个:
我的意思是
neighbors
不是指针,它只是一张 Map . 对于boardTile*
,您将需要new
,这是一个指针 .neighbors
不是指针尝试分配指向
map<char,boardTile*>
的指针,该指针不正确 . 您可以使用对于你的构造函数 .