【发布时间】:2015-02-25 13:46:14
【问题描述】:
我正在尝试使用新的 decltype 关键字将一些代码移动到模板中,但是当与取消引用的指针一起使用时,它会产生引用类型。 SSCCE:
#include <iostream>
int main() {
int a = 42;
int *p = &a;
std::cout << std::numeric_limits<decltype(a)>::max() << '\n';
std::cout << std::numeric_limits<decltype(*p)>::max() << '\n';
}
第一个numeric_limits 有效,但第二个抛出value-initialization of reference type 'int&' 编译错误。如何从指向该类型的指针中获取值类型?
【问题讨论】:
标签: c++ c++11 reference decltype