【发布时间】:2012-12-16 10:45:02
【问题描述】:
我正在阅读this article on Wikipedia regarding C++11 Type Inference feature。
有一个例子,我引用:
#include <vector>
int main() {
const std::vector<int> v(1);
auto a = v[0]; // a has type int
decltype(v[1]) b = 1; // b has type const int&, the return type of
// std::vector<int>::operator[](size_type) const
auto c = 0; // c has type int
auto d = c; // d has type int
decltype(c) e; // e has type int, the type of the entity named by c
decltype((c)) f = c; // f has type int&, because (c) is an lvalue
decltype(0) g; // g has type int, because 0 is an rvalue
}
在以下几行中:
decltype(c) e; // e has type int, the type of the entity named by c
decltype((c)) f = c; // f has type int&, because (c) is an lvalue
c 和 (c) 有什么区别?为什么(c) 代表一个左值?
【问题讨论】:
-
那不是运算符...
-
如果将
int更改为int&,那就是运算符。 -
@MBZ:这并不能使它成为任何“操作员”。