C++ Arrays | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

C++ Arrays

Is there a type of array in C++ that can hold different types of data? (Like lists in Python)

23rd May 2018, 7:05 PM
Zuke
Zuke - avatar
9 Answers
+ 2
Not really, but a clever idea is to create a base class for all other types and make an array of that type. This way, all of thoae elwments can be stored there as pointers of the base class. For other things, I do not think so, but not sure
23rd May 2018, 7:09 PM
Paul
+ 2
Okay, I'll have to learn more about those, thanks!
23rd May 2018, 7:14 PM
Zuke
Zuke - avatar
+ 2
You can create a Union for all different types. That dont use so much memory such a Class or a Struct.
23rd May 2018, 9:22 PM
XiLef
+ 1
You mean, using templates?
23rd May 2018, 7:10 PM
Zuke
Zuke - avatar
+ 1
If i dont rember awrong, Boost has some ds for this
23rd May 2018, 7:55 PM
KrOW
KrOW - avatar
0
nono, like creating a class A and derive that class in other classes
23rd May 2018, 7:12 PM
Paul
0
Additionaly, if you would need a dictionary in c++, there is a std::map, maybe that helps a little too
23rd May 2018, 7:13 PM
Paul
0
Np, have a great coding time!!
23rd May 2018, 7:16 PM
Paul
0
Hello everyone, could someone give me an example of how it works? I can hardly imagine. int x[3][3][2]= ? int x[3][3][2]={{{},{}},{{},{}},{{},{}}} Like this? but where place values??? I just don't think I'll ever use that ..
12th Jul 2020, 11:57 AM
Alain Mazy
Alain Mazy - avatar