Hey guys,
So I am messing around with the Curiously Recurring Template Pattern, and was wondering:
is there a way to access a 'base class' that uses CRTP to call functions?
for example:
template<typename C>
class Entity
{
private:
//helper function for polymorphic functions
C* getChild()
{
return static_cast<C*>(this);
}
public:
Entity() {}
void paint()
{
getChild()->display();
}
}
//...
//another question: can vectors hold templated types?
template<typename T>
std::vector< Entity<T>* > entities;
int main()
{
for(auto i : entities){
i->paint();
}
}
i'm trying something similar and it's not working.
this is the only stackoverflow question i could find that is related:
Note: I'm not actually deving, but am playing around with the CRTP to learn it. Otherwise I'd strongly adhere to KISS