I have question regarding interaction between auto and initializer list. Example code:
#include <iostream>
int main()
{
auto a{ 1 };
auto b = { 1 };
auto c = 1;
std::cout << typeid(a).name() << std::endl;
std::cout << typeid(b).name() << std::endl;
std::cout << typeid(c).name() << std::endl;
return 0;
}
Gives output:
int
class std::initializer_list<int>
int
Which is kind of confusing. I'm posting this question as a followup to this. What should happen? I've did some research and it seems that auto c = 1;
is illegal now, and it seems that it works because compilers allow this as a backwards compatibility patch. Does this apply also to auto a{1}
?
Aucun commentaire:
Enregistrer un commentaire