This question already has an answer here:
I'm trying to iterate an initializer_list to give values to class elements like this:
int main(){
struct S{
int i1;
int i2;
int i3;
S(const initializer_list<int>& l){
i1=l[0];
i2=l[1];
i3=l[2];
}
}
auto l={1,2,3};
S obj=l;
return 0;
}
Well, it doesn't compile. I just wish to know if initializer_list support to work like an array? Thanks.
Aucun commentaire:
Enregistrer un commentaire