To start, I will present my problem, and then explain the possible solutions I can't seem to implement properly.
Problem: I have a basic struct (shown below), that all objects inherit from. I also have a simple derived class that I want to add to a static list on creation.
However, I would like for there to be separate lists created for each object type.
So, I would like a list to be created for every type of object...even new ones that someone creates, which eliminates the possibility of creating a static list of objects to add to for every object type.
Code:
struct Base
{
protected:
int ID;
}
Code:
class Derived1
{
public:
Derived(int x):ID(x) {}
};
Code:
class Derived1
{
public:
Derived(int x):ID(x) {}
};
Using this structure, how could I dynamically create lists for the derived1 and derived2 classes?
I thought that I could create a list of lists of type T, like so:
Code:
template<class T> static List<List<T>> Lists
then populate it like this:
Code:
if(Lists.Contains(List<Derived1>)
{
Lists.Get(List<Derived>).Add(derived1);
}
else
{
Lists.Add(List<Derived>());
Lists.Get(List<Derived>).Add(derived1);
}
however...this is pure psuedocode, and apparently you can't create an list of lists of type T....
...does anyone know a standard or intelligent solution to this? Creating dynamic lists, for every type created, to store and track every custom object in your program...
Seems like something that would be incredibly useful. Let me know if you guys find anything!