I'm having a bit of trouble working on my current project. The project consists of taking lines of data from a file and creating an array of class objects that all inherit a base class.
So, this is what I understand so far:
class BaseClass {
// create empty and non-empty constructor
}
class SubClass : public BaseClass {
// create constructor specifically for this class
}
int main() {
BaseClass *array[size];
array[index] = new SubClass();
return 0;
}
Since the SubClass inherits the BaseClass, When I add a new object to the array it should be of type SubClass, correct?
When I debug the program and look at that object, it doesn't allow me to point to any of the SubClass methods/variables for manipulation which is what I need to be able to do.
Now when I was searching for answers I came across static casting, so I tried it to the extent of:
(static_cast<SubClass*>(array[index])->subclass_variable) = some_value
But that doesn't seem to work either, any help with this would be greatly appreciated.