尽可能多地使用auto,以便更灵活地更改代码中的数据类型,这是不是一个好主意?比如,如果你使用了一堆基于范围的for循环,那么总是使用auto是不是很有效,这样你就再也不用回过头来改变for循环的数据类型了?
发布于 2016-07-22 14:42:09
简而言之,是的。有关详细信息,请参阅此AAA。但是,请注意一些类似的情况:
int x = 4;
int& ref = x;
auto y = ref;y现在是int而不是int&
const int x = 5;
auto y = x;y is int not const int;
https://stackoverflow.com/questions/38519326
复制相似问题