首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不正确/错误地使用typetraits C++

不正确/错误地使用typetraits C++
EN

Stack Overflow用户
提问于 2016-03-27 04:28:13
回答 1查看 114关注 0票数 3

我正在尝试使用typetraits enable_if,但我在语法方面可能有一些问题……

代码语言:javascript
复制
#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;
}

错误是:

代码语言:javascript
复制
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有什么关系吗?我的代码应该如何修复才能工作?

EN

回答 1

Stack Overflow用户

发布于 2016-03-27 04:44:46

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36240528

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档