Reputation: 326
I have a template class (A). How can I force template argument to have an specific function?
template <class T>
class A
{
} ;
T should have specific function.
Thanks
Upvotes: 0
Views: 97
Reputation: 98974
If your template code uses the function, compilation will already fail if T
doesn't have it.
But if your goal is to provide clearer error messages to the users of A
, you can use static asserts based on checks on T
having that member. Note however that you have to watch out for inherited functions.
Upvotes: 1