简体   繁体   中英

Bad/Wrong use of typetraits C++

I'm trying to use the typetraits enable_if but I have some troubles with the syntax probably...

#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;
}

The error is:

1>c:\users\lukkio\documents\visual studio 2015\projects\templates\templates\templates\header.h(19): error C3860: template argument list following class template name must list parameters in the order used in template parameter list

I'm using visual studio 2015 on windows. Is it related to SFINAE somehow? How should my code be fixed to work?

正如您可以在默认模板参数http://en.cppreference.com/w/cpp/language/template_parameters#Default_template_arguments下阅读的那样,默认模板参数不应指定两次,因此如果您在typename = ...后删除部件..在构造函数中,我相信它应该工作

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM