简体   繁体   English

带有 typedefed 元素的 C++ 数组

[英]C++ Array with typedefed elements

Can typedefs which refer to the same type be mixed together in an array?引用相同类型的 typedef 可以混合在一个数组中吗?

typedef double seconds;
typedef double meters;

Would I be able to make an array that can contain both seconds and meters?我能制作一个可以同时包含秒和米的数组吗?

double sec_met[2] = {variable_with_type_seconds, variable_with_type_meters};

The logical answer would be yes, since the typedefs are mere aliases for types, and hence the datatype would still be the same.合乎逻辑的答案是肯定的,因为 typedef 只是类型的别名,因此数据类型仍然相同。

Short answer: Yes.简短的回答:是的。

Longer answer: Yes since a typedef is an alias.更长的答案:是的,因为typedef是别名。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM