`using my_type = unsigned;` vs `using my_type = unsigned int;` 在 C++ 中

`using my_type = unsigned;` vs `using my_type = unsigned int;` in C++

在 C++ 中,以下两个代码片段是否等效?

    using my_type = unsigned;
    my_type variable;

    using my_type = unsigned int;
    my_type variable;

如果是,为什么还要定义 my_type 而不是使用 unsigned 甚至 unsigned int?考虑到后两者有点长,但更明确,什么时候定义和使用 my_typeunsigned and/or unsigned int?

是的,它们是相同的。使用 my_type 可以使意图更明确。例如。考虑 using celsius = int;

为了获得更好的类型安全性,您可以使用新类型模式(Google),但在 C++ 中它有点乏味。

选择unsigned vs unsigned int只是品味