+ 2

c++ array of multiple data type

Anyone knows how to having an array with multiple data type inside of the array? example: in python, Javascript, etc we can: ItIsArray=[12, 0.5,"string"] But if in c++, we can't do the code below, right? int ItIsArray={12, 0.5,"string};// return error how to do it? Thanks.

9th Apr 2018, 6:40 AM
Immanuel
Immanuel - avatar
3 Answers
+ 1
You cannot make multiple data type arrays in probably any language. If there is not too much different data types then you can make tuples or your own structures.
9th Apr 2018, 6:53 AM
Bartosz Pieszko
Bartosz Pieszko - avatar
+ 1
This is why I love JavaScript.arrays can have different data types
9th Apr 2018, 7:22 AM
᠌᠌Code X
᠌᠌Code X - avatar
0
For a shortcut, you may try using arrays of custom defined unions or classes.
9th Apr 2018, 9:11 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar