Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我了解到以这种方式使用 auto 声明变量
auto var = expr;
基本上就像expr从它那里获取和剥离 &/&&-references 和所有顶级常量和易失性的类型。这是否意味着上述行完全等同于以下行?
expr
std::remove_cv<std::remove_ref<decltype(expr)>::type>::type var = expr;
不,那不是真的。auto var = expr;更像是expr按值传递。
int x[1]; auto y = x;
这y使得int*.
y
int*
主要auto x = expr;表现得像模板类型推导:
auto x = expr;
template <typename T> void f(T); int x[1]; f(x); // deduces T as int*
它更像std::decay<decltype(expr)> var = expr;。
std::decay<decltype(expr)> var = expr;