Chess piece hierarchy design: inheritance vs type fields

前端 未结 6 756
别跟我提以往
别跟我提以往 2021-02-15 13:23

I have a base class for pieces

 class piece;

and an array containing derived objects

piece* board[8][8];

Advantag

6条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-15 14:01

    Alternatively, if your set of classes is limited - i.e. you know the number, use a variant and visitors. For example, boost::variant And the board is made up of a 2D array of this type. Now to interrogate, you can use visitors...

提交回复
热议问题