【发布时间】:2012-08-23 02:41:24
【问题描述】:
据我了解,decltype 和 auto 都会尝试找出某物的类型。
如果我们定义:
int foo () {
return 34;
}
那么这两个声明都是合法的:
auto x = foo();
cout << x << endl;
decltype(foo()) y = 13;
cout << y << endl;
您能告诉我decltype 和auto 之间的主要区别是什么吗?
【问题讨论】:
-
@JesseGood 在问这个问题之前,我阅读了那个帖子并正在寻找一个更清晰的解释
-
@JamesLeonard:好吧,我不知道更好的解释than the one by Scott Meyers。
-
Scott Meyers 在 youtube.com/watch?v=wQxj20X-tIU&t=1468s 中明确解释过
标签: c++ type-inference