相关疑难解决方法(0)

模板重载和SFINAE只能处理函数而不能处理类

有人可以解释为什么编译器只接受这个代码

template<typename L, size_t offset, typename enable_if< (offset<sizeof(L)), int >::type =0>
void a_function(){}

template<typename L, size_t offset, typename enable_if< (offset==sizeof(L)), int >::type =0>
void a_function(){}
Run Code Online (Sandbox Code Playgroud)

但不是这个:

template<typename L, size_t offset, typename enable_if< (offset<sizeof(L)), int >::type =0>
class a_class{};

template<typename L, size_t offset, typename enable_if< (offset==sizeof(L)), int >::type =0>
class a_class{};
Run Code Online (Sandbox Code Playgroud)

编译器将第二个类模板视为第一个类的重新定义.

c++ templates sfinae c++11

17
推荐指数
1
解决办法
3028
查看次数

标签 统计

c++ ×1

c++11 ×1

sfinae ×1

templates ×1