【发布时间】:2014-05-04 21:55:45
【问题描述】:
以下代码不起作用。它的目的是将参数传递给可变参数基类。这是否可能,如果可以,实现它的正确方法是什么? (Clang的报错信息是:an initializer for a delegating constructor must appear alone,看不懂。)
template<class... Visitors>
class Visited: public Visitors...
{
public:
template<class F>
Visited(const F& f): F(f) {}
template<class F, class... Rest>
Visited(const F& f, const Rest&... r):
F(f), Visited(r...) {}
};
struct A {};
struct B {};
struct C {};
int main()
{
A a;
B b;
C c;
Visited<A,B,C> v(a, b, c);
}
【问题讨论】:
-
错误只是说如果你委托给另一个构造函数,你不能初始化该列表中的任何其他内容。
-
那么有没有办法做我想做的事,还是没有希望?
-
应该可以吧,不过我没用过可变参数继承,所以不熟悉这种方法。
标签: c++ templates c++11 variadic