C++ 查看auto delctype 后变量的类型。(小技巧)

初学auto,delctype 搞不清楚自动转换后的变量类型

在stackFlow中找到个小技巧来解决这个问题。

template<typename>
struct info;

int main()
{
    int i = 2;
    int *p;
    decltype(*p) q = i; //报错 使用了未定义类型“info<int &>” 
    info<decltype(q)>();
    return 0;
}

 

可通过使用

info<decltype( 变量名 )>(); 

让编译器输出

使用了未定义类型“info< 变量类型 >”

错误信息 来查看变量的类型

 

https://stackoverflow.com/questions/53570664/auto-and-delctypeauto-type-deduction-example

 
原文地址:https://www.cnblogs.com/--zz/p/10427792.html