C++ iterating a struct

后端 未结 4 1715
囚心锁ツ
囚心锁ツ 2021-01-21 10:27

Is it possible to iterate through a struct?

For example

struct team{
   int player1;
   int player2;
   int player3;
   int player4;
   ...
   int player         


        
4条回答
  •  滥情空心
    2021-01-21 11:22

    I would propose to use container instead of many variables, for example you could use std::array or std::vector. This way it will be trivial to iterate, much easier to make a copy. But also it's better from design point of view: in case you decide to change the number of players it will be much easier to change the container rather than add/remove many fields

提交回复
热议问题