类型特征C++使用不当

Bad/Wrong use of typetraits C++

本文关键字:使用不当 C++ 特征 类型      更新时间:2023-10-16

我正在尝试使用类型特征enable_if,但语法可能有一些问题。。。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <type_traits>
template <typename _T, typename = std::enable_if_t<std::is_floating_point<_T>::value> >
struct Point {
    _T x;
    _T y;
    Point();
};
template <typename _T, typename = std::enable_if_t<std::is_floating_point<_T>::value> >
inline Point<_T, std::enable_if_t<std::is_floating_point<_T>::value> >::Point()
{
    this->x = (_T)0.0;
    this->y = (_T)0.0;
}

错误为:

1>c:userslukkiodocumentsvisual studio 2015projectstemplatestemplatestemplatesheader.h(19): error C3860: template argument list following class template name must list parameters in the order used in template parameter list

我正在windows上使用visual studio 2015。它是否与SFINAE有关?我的代码应该如何修复才能工作?

正如您在默认模板参数下看到的那样http://en.cppreference.com/w/cpp/language/template_parameters#Default_template_arguments,默认模板参数不应指定两次,因此如果删除typename=…..之后的部分。。。。。在构造函数中,我认为它应该工作