【发布时间】:2018-03-18 18:52:23
【问题描述】:
谁能帮我理解为什么下面的代码不能编译:
#include <type_traits>
class A{};
class B{};
template< typename T >
class C
{
template< typename = std::enable_if_t<std::is_same<T, A>::value > >
void foo()
{}
template< typename = std::enable_if_t<std::is_same<T, B>::value > >
void foo()
{}
};
错误信息:
t.cpp:15:8: error: class member cannot be redeclared
void foo()
^
t.cpp:11:8: note: previous declaration is here
void foo()
^
1 error generated.
我希望始终只有一个foo 定义处于活动状态; T 的第一个等于A,T 的第二个等于B。
如果有人可以帮助我修复代码,那就太好了。
【问题讨论】:
标签: c++ c++14 sfinae typetraits enable-if