You can use a combination of std::is_floating_point
and std::enable_if
to only enable the function for floating point types:
#include <type_traits>
template <typename T>
class ClassName
{
// instance variables, etc..
public:
template<typename T2 = T,
typename = typename std::enable_if< std::is_floating_point<T2>::value >::type>
void some_method()
{
// do stuff, but only for floating point types
}
};
int main()
{
ClassName<double> d; // OK
d.some_method(); // OK
ClassName<int> i; // OK
i.some_method(); // ERROR
}