//a.h
class a{
};
//b.h inherits from a
class b: public a{
private:
int var;
public:
b(int); //sets var as the int
int getVar(); //returns var
};
//c.h inherits from a
class c: public a{
private:
int var;
public
c(int); //sets var as the int
int getVar(); //returns var
};
//main.cpp
vector<a> aArray;
for(int i = 0 ; i < 5 ; i++){
int randVal = rand()%2;
if(randVal==0){
b B(randVal);
aArray.push_back(;
}
else{
c C(randVal);
aArray.push_back©;
}
}
for(int i = 0 ; i < 5 ; i++){
a A = aArray;
//my problem, how would I know that a is actually b or c? Since b and c both are sub classes of c
}
basically after storing them in a vector, I want them to be able to be taken out in the same type as they were put in with.
Any ideas? </a><div><a>I want to take them out of the vector aArray as either an object of type b or type c then use getVar to retrieve the values</a></div><div><a>Thanks a lot.
</a>
</div>