lundi 3 décembre 2018

variable type during list initialization using auto

Does using auto for list initialization of variables uses correct type? For example,

#include <iostream>
#include <typeinfo>

int main()
{
  auto v1 = {13};
  auto v2 = 14;

  std::cout<<typeid(v1).name()<<std::endl;
  std::cout<<typeid(v2).name()<<std::endl;
  return 0;
}

Output is :

St16initializer_listIiE
i

Question: Why v1 is list?

Aucun commentaire:

Enregistrer un commentaire