我正在尝试使用typetraits 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:\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我在windows上使用的是visual studio 2015。它与SFINAE有什么关系吗?我的代码应该如何修复才能工作?
发布于 2016-03-27 04:44:46
正如您可以在此处的默认模板参数http://en.cppreference.com/w/cpp/language/template_parameters#Default_template_arguments中所读到的,默认模板参数不应指定两次,因此,如果您删除typename = .....在构造函数中,我相信它应该可以工作
https://stackoverflow.com/questions/36240528
复制相似问题