【发布时间】:2020-11-19 12:37:24
【问题描述】:
来自那个问题: Using enum values in combination with SFINAE
我尝试实现:
enum Specifier
{
One,
Two,
Three
};
template <Specifier, typename UNUSED=void>
struct Foo
{
void Bar(){ std::cout << "Bar default" << std::endl;}
};
template <Specifier s , typename std::enable_if<s == Specifier::Two || s == Specifier::One, int>::type>
struct Foo<s>
{
void Bar(){ std::cout << "Bar Two" << std::endl; }
};
int main()
{
Foo< One >().Bar();
Foo< Two >().Bar();
}
失败:
> main.cpp:130:8: error: template parameters not deducible in partial specialization:
130 | struct Foo<s>
| ^~~~~~
main.cpp:130:8: note: '<anonymous>'
如何解决这个超级简单的例子?我喜欢 SFINAE :-)
【问题讨论】:
-
您的代码看起来与您链接的问题的已接受答案中的代码不同
-
@idclev463035818:是的,因为这是我尝试解决的问题。我不明白为什么!
-
也许可以在问题中澄清这一点。我现在明白这是试图回答这个问题,而不是试图应用答案,对吧?
标签: c++ templates sfinae template-specialization