我不明白FCD第148页上的例子的最后一行(§7.6.1.2/ 4):
const int&& foo();
int i;
struct A { double x; };
const A* a = new A();
decltype(foo()) x1 = i; // type is const int&&
decltype(i) x2; // type is int
decltype(a->x) x3; // type is double
decltype((a->x)) x4 = x3; // type is const double&
Run Code Online (Sandbox Code Playgroud)
为什么括号在这里有所作为?它不应该只是double像上面那样吗?
我正在维基百科上C++11 阅读关于类型推断功能的这篇文章.
有一个例子,我引述:
#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 = …Run Code Online (Sandbox Code Playgroud)