Initializer list in a range for loop

后端 未结 2 1044
春和景丽
春和景丽 2021-02-05 15:54

I have objects of different types derived from a single super-type. I wonder if there are any disadvantages in using std::initializer list in a range for loop like

2条回答
  •  庸人自扰
    2021-02-05 15:59

    You can simply write

    for(auto object : {object1, object2, object3}) {
       // work
    }
    

提交回复
热议问题