基本例子

此示例仅说明了如何使用此关键字。

int a = 10;

// Assume that type of variable 'a' is not known here, or it may
// be changed by programmer (from int to long long, for example).
// Hence we declare another variable, 'b' of the same type using 
// decltype keyword.
decltype(a) b; // 'decltype(a)' evaluates to 'int'

例如,如果某人更改,请键入 a 以:

float a=99.0f;

然后变量 b 的类型现在自动变为 float