Given the following code:
struct Window{
void show();
//stuff
}w1, w2, w3;
struct Widget{
void show();
//stuff
}w4, w5, w6;
struct Toolbar{
void show();
//stuff
}t1, t2, t3;
I want to show
a bunch of items:
for (auto &obj : {w3, w4, w5, t1})
obj.show();
However this does not compile since the std::initializer_list<T>
in the for
-loop cannot deduce T
and in fact there is not really a T
that would fit. I don't want to create a type erasure type because of the amount of code required and the unnecessary runtime overhead. How do I correctly write my loop so that the type of obj
is deduced for every item in the conceptual list separately?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…