I'm stuck with a map initialization problem. I want a table to access all the directions of my tetris blocks. I have tried a lot of methods to initialize it, but it seems too complex to be initialized.
This is the error info this time:
错误 C2440 “初始化”: 无法从“initializer list”转换为“std::map,std::allocator<_Ty>>,std::allocator>>>,std::less<_Kty>,std::allocator>,std::allocator>>>>>>” WinApp c:\codes\learning\winapp\tetris.cpp 44
I wonder how to initialize this table.
in my block
class:
typedef std::map<shapes, std::vector < std::vector<std::pair<int, int> > > > proj;
static proj dirs ;
in the .cpp file:
block::proj block::dirs =
{
{ 6,{ { TL, TC, MR },{ TC, ML, BL } } },
{ 4,{ { TR, TC, ML },{ TC, MR, BR } } },
{ 5,{ { ML, MR, BC },{ TC, MR, BC },{ TC, ML, MR },{ TC, ML, BC } } },
{ 3,{ { TL, TC, ML } } },
{ 2,{ { { ML, BL, MR },{ TC, BC, BR },{ TR, ML, MR },{ TL, TC, BC } } } },
{ 1,{ { ML, BR, MR },{ TR, TC, BC },{ TR, TC, BC },{ TL, MR, ML },{ TC, BC, BL } } },
{ 0,{ { ML, MR,{ 2,0 },{ TC, BC,{ 0,2 } } } } } // sticks out
};
I defined the pairs as const vars for short.
const std::pair<int, int> TL{ -1,-1 }; /* top left */
const std::pair<int, int> TC{ 0,-1 }; /* top center */
const std::pair<int, int> TR{ 1,-1 }; /* top right */
const std::pair<int, int> ML{ -1,0 }; /* middle left */
const std::pair<int, int> MR{ 1,0 }; /* middle right */
const std::pair<int, int> BL{ -1,1 }; /* bottom left */
const std::pair<int, int> BC{ 0,1 }; /* bottom center */
const std::pair<int, int> BR{ 1,1 }; /* bottom right */
Aucun commentaire:
Enregistrer un commentaire