class A
{
protected:
map<int, A*> database;
string something;
public:
A(){}
~A(){
//deletes all items in database
}
void showDatabase()
{
//some loop that iters through the map to print out whats in it
}
};
class B : public A
{
public:
B(newsomething){something = newsomething;}
void BAddData()
{
database[10] = new B(some);
}
};
class C : public A
{
C(newsomething){something = newsomething;}
void CAddData()
{
database[30] = new C(some);
}
};
main function
1 2 3 4 5 6 7 8 9 10 11 12
int main()
{
A a;
B b;
C c;
b.BAddData();
c.CAddData();
a.showDatabase();
return 0;
}
i have something similar to this but the problem i have is that nothing going into the map.
i have an idea why the database shows up as empty its because im calling showdatabase in separate instance from the other 2. im just curious how to add items to the map that is declared in the base class and the items remain there until the program ends