相关疑难解决方法(0)

decltype和括号

我不明白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++ type-inference decltype c++11

50
推荐指数
3
解决办法
3617
查看次数

括号中的括号的重要性((c))?

我正在维基百科上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)

c++ decltype c++11

34
推荐指数
2
解决办法
3421
查看次数

标签 统计

c++ ×2

c++11 ×2

decltype ×2

type-inference ×1