I have a need to add the total of one of the variables for each of the derived classes I have.
I think this has something to do with dynamic_cast?
Code:
class Base
{
privat:
int trackTime;
}
class raceCar : public Base
{}
class crapCar : public Base
{}
int main()
{
Base *carList[10];
// Create some raceCars and crapCars
.....
int raceCarTotalTime = 0;
int crapCarTotalTime = 0;
for(carList)
{
if(carList[i] == raceCar)
raceCarTotalTime += carList[i]->getTime();
else
crapCarTotalTime += carList[i]->getTime();
}
}