Is it possible to store multiple different class types in a single std::list object?
I want to make multi-layered list that can store int and std::list as an element, and now am trying to use std::list for this purpose. I need to retrieve data from all the list from both top-level and subsequent layers too.
This question here is similar except that I want to use pre-defined class.
The following returns error at 4th line:
std::list<int> l;
std::list<int> subL;
l.push_back(1);
l.push_back(subL);
This returns error at 1st (and 3th according to the 1st line):
std::list l;
std::list<int> subL;
l.push_back(1);
l.push_back(subL);
You could declare
list <void*>and store to it pointers to any of your objects. But another question will raise how you’re going distinguish them to use? If you don’t need to, it’s OK.