【发布时间】:2018-03-28 14:18:22
【问题描述】:
如何编译这段代码?
struct type1 {};
struct type2 {};
struct handler1
{
void handle(type1){}
};
struct handler2
{
void handle(type2){}
};
template <typename... Handlers>
struct TheHandler : Handlers...
{
using Handlers::handle...; // DOESN'T COMPILE
};
TheHandler<handler1, handler2> handler;
handler.handle(type1());
【问题讨论】:
-
This works in C++17。它是在 C++17 中添加的(
using扩展参数包)。它在 C++14 中作为编译器扩展工作 -
@Justin 谢谢,但我暂时坚持使用 C++14。
-
与所有参数包扩展一样,如果我没记错的话,你可以用递归重写它
-
是的,您可以按照使用
using:open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0195r1.html 提出参数包扩展的论文用递归重写它
标签: c++ c++11 c++14 variadic-templates using-declaration