I have a fruit class and a apple which inherits from the fruits.
Lets say i have an array of individual sorts of fruits. I could say apples, bananas and other fruits.
The problem: When i try to get the values from an element of that array (a child of fruit) it won't compile.
class Fruit{
public:
Fruit();
}
class Apple : public Fruit{
public:
Apple();
int count; //number of apples in the store
}
int main(){
Fruit market[3];
market[0] = Apple();
int apples = market[0].count;
}
I know that this is because the program doesn't know that it is looking at an apple; But if i certainly know that it is an apple (through checking for example), how can i access Apple.count?