Hello! I'm trying to write a program which will take in a list of input files. Then create an instance of Class A per input file. Functions will later on create new instances of Class C. But the difficult part is that ClassC must be able to access one of the members(a lookup table) of a
specific classA object.
Code:
//main.cc
vector<A*> list_of_As;
some_function{
for ( list of file names)
{
A * temp;
temp = new A;
do_something(temp);
list_of_As.push_back(temp);
}
}
do_something(A * temp)
{
C * temp;
temp = new C(A);
//Class C object then uses member variable of the class A object the loop is currently on. Not just any class A object! THIS specific one.
...
}
//--
//a.cc
class A
{
public:
A(){}
vector < string > Lookup_Table; //Justa an example, chose a random data structure.
};
//--
//others.cc
class A; //Forward declaration?
//Abstract base class for numerous derived classes. (later on)
class B
{
public:
B(){}
// This constructor will be called by derived class.
B(A * temp)
{
*Lookup_Table = temp->Lookup_Table; //Set this base classes' variable, so the calling derived class's will have access to class A's Lookup_Table
}
void base_function()=0;
vector<string> * Lookup_Table;
int members;
}
class C: public B;
{
public:
c(){}
C(A * temp):B(temp){} //Here we pass the A* to the base class's constructor which will point our Lookup_Table to that of this specifc class A object's.
void base_function()
{
Lookup_Table ... do something with it.
//Important thing is that we are now accessing the member variable from class A!!
}
}
//--
eh... i dunno if i made it clear enough. I'm doing this because I need to create multiple lookuptables, one per file. Each lookup table will be different depending on what is in the file. But setting the lookuptable is done elsewhere... right now in class B! How can i do this...? maybe a bad design...?
thanks for any insight...