【发布时间】:2017-04-07 12:11:31
【问题描述】:
为什么以下在 C++ 中是非法的?
auto x = unsigned int(0);
而以下都可以:
auto y = int(0);
auto z = unsigned(0);
auto w = float(0);
或一般来说:
auto t = Type(... c-tor-args ...);
(Type 为 unsigned int 除外)。
【问题讨论】:
-
当然你可以说'auto a = 10u',但你可能知道。您使用的语法与构造无关,即使它表面上类似于它。使用正确类型的文字,就是这样。
标签: c++ type-conversion language-lawyer