I have two classes like below :
class Plot
{
protected:
virtual void plot() = 0;
}
class DynamicPlot : public Plot
{
public:
virtual void update_real_time();
virtual void plot();
}
class StaticPlot : public Plot
{
public:
virtual void plot();
}
And a container like this:
std::vector<Plot*> plot_vector;
plot_vector.append(new DynamicPlot());
plot_vector.append(new DynamicPlot());
plot_vector.append(new StaticPlot());
plot_vector.append(new StaticPlot());
And i want to call update_real_time() if the type of the instance is DynamicPlot.
foreach(Plot *plot, plot_vector)
{
if(/* plot type == DynamicPlot */)
{
plot->update_real_time();
}
plot->plot();
}
Which pattern should i use here ? Adding an empty update_real_time() method into the StaticPlot class doesn't seem like a good solution.
EDIT : The code above is not real. I just wrote it in order to tell my problem, think that as a psuedo code. I didn't bother to write access qualifiers. In my real code, i do not have a private inheritance or slicing issue. I keep pointers of instances in vector. Sorry for misunderstanding. I am fixing it anyway.