Is there any possibility to force a template to be from a certain base class so that I can call the base class function?
template <class T> void SomeManager::Add(T) { T->CallTsBaseClassFunction(); //... do other stuff } Sure, you can combine type traits with SFINAE:
#include <type_traits> template <class T> typename std::enable_if<std::is_base_of<your_base_class, T>::value, void>::type SomeManager::Add(T) { T->CallTsBaseClassFunction(); //... do other stuff } Although I don't really see the benefit here.
void handle(T t) { this.processData(t.getValue());}. Other people can develop different data, such as class DataTypeA, class DataTypeB. Now, you must force the writer of DataTypeA and DataTypeB to write the member function getValue(). To do so, you can write an abstract class, containing an abstract function getValue(). If DataTypeA didn't inherit the abstract class, generate an ERROR.DataTypeA doesn't have getValue(), it would still error.Worth to mention that it can be done at compile time in a more readable fashion with static_assert. Something in the lines of:
class Base {}; template<class B> class Template{ static_assert(std::is_base_of<Base, B>::value, "B must derive from nmspc::Base"); } 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.
Random::CallTsBaseClassFunctionifclass Randomjust happens to implement a function by the same name.