I have a class that is derived from another, I use an array of base class pointers to hold instances of the derived class, but because the array is of the base class, I cannot access members belonging to the derived class with pointer notation, is it possible for me to access these members with a simple command or should I just rewrite my base class to define the member and only use it in the derived class?
Example:
class A {
public:
int foo;
};
class B : public A {
public:
char bar;
};
class C : public A {
int tea;
};
int main() {
A * arr[5];
arr[0] = new B;
char test = arr[0]->bar; //visual studio highlights this with an error "class A has no member bar"
return 0;
}