I’d like to make two base classes (e.g. figure and move) with some children for each one(cube, sphere and so on for figure; shift, rotate, rescale and so on for moves). Initial number of figures and moves is unknown – it must be expandable. Each move should know how to move each figure, so having N figures and M moves means to have N*M function for them. (Adding a move requires creation of N functions for each already existing figure and adding figure requires creation of M functions for each already existing move).
The question is how to declare theese functions? For example, I’ll have a class Set containing list of figures (aka vector) and I need to ask this class to move all the figures by i-th move. Probably set would have a method of
set::move_all (const move& )
and… well what next? The easiest idea is to create virtual method
class figure {
...
virtual void move_this (const move& )
...
}
to call a virtual method move_figure
class figure_i: public figure {
...
virtual void move_this (const move& M)
{M.move_figure(*this);
}
...
}
class move {
...
template <class T> virtual void move_figure (T&) const
...
}
and specialize it for each i-th move like this
template <> void shift::move_figure <cube> (cube& C)
{
}
and so on, but virtual templates are illegal.
Well, my current solution is to use typeid/typeinfo to identify figure/move pair and call corresponding function (non-member) to move figure by this move from global object of map type like this
and somewhere
and, of course
so unlike case of using templates, everything is independent and well expandable.