I have just read an article about the Curiously Recurring Template Pattern. And you can use it simulate virtual function with templates.
For example:
template<class T>
struct A
{
void func() { static_cast<T*>(this)->func(); }
};
struct B : public A<B>
{
void func() { cout << "B" << endl; }
};`
However, if we have many subclasses from A and want to put them all in vector,
for example vector<A*>
this is not possible when you use templates and you have to use normal polymorphism with virtual functions in the base class.
Does anyone have a design suggestion to solve this? Because I want to use templates but also be able to but all subclasses together in a container.