0

Array (or List, Vector) with Multi Data types in C++

Hi, I've a question. How can i declare Array with multi data types? For example: (smth) arr = {1, 3.14, true, ...};

24th Jan 2021, 6:50 PM
Arslan Annayew
Arslan Annayew - avatar
2 Answers
+ 8
You can use an array/vector of the std::variant type. There is 1 restriction though - you need to give all the types you will be using as type arguments and you *cannot* use any other type other than the ones you've listed https://en.cppreference.com/w/cpp/utility/variant Example: https://code.sololearn.com/ckHJtsCdBPof/?ref=app
24th Jan 2021, 7:21 PM
XXX
XXX - avatar
0
Thanks for fast answer!
25th Jan 2021, 5:11 PM
Arslan Annayew
Arslan Annayew - avatar