类型特征C++使用不当
Bad/Wrong use of typetraits C++
我正在尝试使用类型特征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=…..之后的部分。。。。。在构造函数中,我认为它应该工作
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- C++:TypeDef使用元组
- 使用std::multimap迭代器创建std::list
- 从不同线程使用int64的不同字节安全吗
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 为什么在全局范围内使用"extern int a"似乎不行?
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 如何使用Google Mock来模拟gettimeofday()
- 如何使用默认参数等选择模板专业化
- 使用宏扩展的泛型:为什么指令缓存使用不当?
- 互斥 c++ 使用不当
- 返回功能的使用不当
- 由于指针使用不当而导致的未上线异常
- 类型特征C++使用不当
- 带有继承的new使用不当
- system()调用使用不当
- 模板使用不当
- c_str使用不当
- 为什么这个initializer_list在传递字符串时使用不当行为