AmirC
AmirC

Reputation: 326

force a template argument to have specific operator

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

Answers (1)

Georg Fritzsche
Georg Fritzsche

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

Related Questions