is there apossibility to force a template to be from a certain base class, so i can call the base class function?
template <class T>
void SomeManager::Add(T)
{
T->CallTsBaseClassFunction();
//... do other stuff
}
is there apossibility to force a template to be from a certain base class, so i can call the base class function?
template <class T>
void SomeManager::Add(T)
{
T->CallTsBaseClassFunction();
//... do other stuff
}
The easiest solution is to add a snippet of code that compiles only if it's what you expected:
Sure, you can combine type traits with SFINAE:
Although I don't really see the benefit here.
Worth to mention that it can be done at compile time in a more readable fashion with static_assert. Something in the lines of:
It works even when B is exactly Base. If Base is itself a templated class it becomes more complicated but it can still be done and there's plenty of resources online.