这个关键字可以推断出表达式的类型。
struct
{
int frist = 2;
int second = 3;
}ceshi;
上面是一个匿名结构体对象,变量名是ceshi,类型不知道。如果要使用这个结构体的类型,就用到了decltype:
decltype(ceshi)
创建一个同类型的对象并赋值返回:
struct
{
int frist = 2;
int second = 3;
}ceshi;
decltype(ceshi) deduce()
{
decltype(ceshi) c;
c.frist = 66;
c.second = 8;
return c;
}
#define debug qDebug()<<
int main(int argc, char *argv[])
{
debug ceshi.frist << ceshi.second;
auto c = deduce();
debug c.frist << c.second;
}