#include <iostream>
template<typename DTTYPE>
class TM
{
public:
template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
T is_even (T i);
};
template<typename DTTYPE> template<typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type > T TM<DTTYPE>::is_even(T i)
{
return 2*i;
}
int main()
{
TM<double>a;
std::cout << "i is even: " << a.is_even(3.0) << std::endl;
return 0;
}
/*
上面的代码无法通过编译,提示说
main.cpp:11:150: error: default argument for template parameter for class enclosing ‘T TM<DTTYPE>::is_even(T)’
name DTTYPE> template<typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type > T TM<DTTYPE>::is_even(T i)
如果写成内联函数就可以了通过编译了,下面的代码可以编译。请问问题在哪。谢谢!
*/
#include <iostream>
template<typename DTTYPE>
class TM
{
public:
template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
T is_even (T i){return 2*i;}
};
int main()
{
TM<double>a;
std::cout << "i is even: " << a.is_even(3.1) << std::endl;
return 0;
}
--
FROM 210.26.113.*