你会得到这样的东西(我还没有添加向量,但这增加了初始化的额外{}级别)。我只是想给你一个主意
#include <string>
#include <map>
enum class Piece
{
Pawn,
Bishop,
Rook
};
enum class Color
{
Black,
White
};
struct Direction
{
int horizontal;
int vertical;
};
struct Movement
{
Color color;
Direction direction;
};
int main()
{
std::map<Piece,Movement> moves{
{ Piece::Pawn, // <- key of your map, e.g. a Piece enum value
{
Color::White, // First member of Movement, e.g. Color enum value
{0,1} // Second member of Movement, Direction {0 horizontal, 1 vertical)
}
},
{ Piece::Bishop, { Color::Black, {8,8} } }
};
return 0;
}