C++ template for class children possible?
You need no template. If ICtl
has a virtual method called SetPos
you can pass instances of derived classes via reference to the base:
void set(ICtl& pCtl, int x, int y)
{
pCtl.SetPos(x,y);
}
However, it is unclear what purpose this method serves, because now the caller has to call set(pctl,x,y)
when they can simply call pctl.SetPos(x,y)
directly.
Roughly speaking, you would need a template if you wanted to call a method called SetPos
on instances of otherwise completely unrelated types. When the instances share a common base that offers the interface you want to use, there is no need for a template.