Search code examples
c++arraystypesdoubletypedef

C++ Array with typedefed elements


Can typedefs which refer to the same type be mixed together in an array?

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.


Solution

  • Short answer: Yes.

    Longer answer: Yes since a typedef is an alias. :)