gpt4 book ai didi

c++ - 类型特征 C++ 的错误/错误使用

转载 作者:太空狗 更新时间:2023-10-29 21:38:03 25 4
gpt4 key购买 nike

我正在尝试使用类型特征 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 有什么关系吗?我的代码应该如何修复才能正常工作?

最佳答案

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

关于c++ - 类型特征 C++ 的错误/错误使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36240528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com