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, ...};
2 Respostas
+ 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
0
Thanks for fast answer!