C++ - How to call a member function for an inherited object.
- by Francisco P.
Hello!
I have a few classes (heat, gas, contact, pressure) inheriting from a main one (sensor).
I have a need to store them in a vector<Sensor *> (part of the specification).
At some point in time, I need to call a function that indiscriminately stores those Sensor *. (also part of the specification, not open for discussion)
Something like this:
for(size_t i = 0; i < Sensors.size(); ++i)
Sensors[i]->storeSensor(os) //os is an ofstream kind of object, passed onwards by reference
Where and how shall storeSensor be defined?
Is there any simple way to do this or will I need to disregard the specification? Mind you, I'm a beginner!
Thanks for your time!