相关疑难解决方法(0)

decltype vs auto

据我了解,双方decltypeauto会尝试找出的东西是什么类型.

如果我们定义:

int foo () {
    return 34;
}
Run Code Online (Sandbox Code Playgroud)

然后这两个声明都是合法的:

auto x = foo();
cout << x << endl;

decltype(foo()) y = 13;
cout << y << endl;
Run Code Online (Sandbox Code Playgroud)

你能否告诉我decltype和之间的主要区别auto是什么?

c++ type-inference

43
推荐指数
2
解决办法
1万
查看次数

auto和decltype之间的关系

auto x = initializer;
Run Code Online (Sandbox Code Playgroud)

相当于

decltype(initializer) x = initializer;
Run Code Online (Sandbox Code Playgroud)

要么

decltype((initializer)) x = initializer;
Run Code Online (Sandbox Code Playgroud)

还是两个?

c++ type-inference decltype auto c++11

34
推荐指数
3
解决办法
3504
查看次数

标签 统计

c++ ×2

type-inference ×2

auto ×1

c++11 ×1

decltype ×1