我正在尝试使用新的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&'
的编译错误。我该如何从指向该类型的指针获取值类型?
::type
中返回已翻译的文本。 - vsoftco