auto x = 27;//auto代表一个类型,x也有一个类型。 //x=int auto=int
传值方式(非指针,非引用)
auto后面直接接变量名,这叫传值方式
1 2 3 4 5 6 7 8 9 10 11 12 13
auto x = 27; constauto x2 = x;//估计x2 = const int ,auto int constauto& xy = x;//这个auto并不是传值方式,估计xy=const int &,auto =int auto xy2 = xy;//估计xy2=int,auto = int
using boost::typeindex::type_id_with_cvr; cout << "x2=" << type_id_with_cvr<decltype(x2)>().pretty_name() << endl; //xy=const int
using boost::typeindex::type_id_with_cvr; cout << "xy=" << type_id_with_cvr<decltype(xy2)>().pretty_name() << endl; //xy=const int &
using boost::typeindex::type_id_with_cvr; cout << "xy2=" << type_id_with_cvr<decltype(xy2)>().pretty_name() << endl; //xy2=int
总结传值方式对auto类型:会抛弃引用、const等修饰符
指针或引用类型但不是万能引用
auto后面接一个&
1 2 3 4 5 6 7 8
auto x = 27; constauto& xy = x;
auto& xy3 = xy; //xy3 = int const & auto y = newauto(100); //y = int* constauto* xp = &x; //xp = int const * auto* xp2 = &x; //xp2= int* auto xp3 = &x; //xp3= int*