【发布时间】:2015-07-05 01:44:19
【问题描述】:
举个例子:
/* Signal Container */
template <typename Ret> class Signal;
template <typename Ret, typename... Args>
class Signal< Ret (Args...) >
{
/* Following Implementation... */
};
/* Emitter Type */
template < template <typename Ret, typename... Args> Signal< Ret (Args...) > ... Sig>
class Emitter
{
// using Signals = std::tuple<Sig...>;
/* Following Implementation... */
};
/* Signals */
using Signal_A = Signal<void()>;
using Signal_B = Signal<void(int)>;
using Signal_C = Signal<void(int, float)>;
/* Desired Usage */
class MyType : public Emitter<Signal_A, Signal_B, Signal_C>
{
};
我希望能够从接受 1 个(0?)或多个 Signal 类型的模板参数的 Emitter 类型继承(并且只有 Signal)。 Signal 是一个模板类型,它的定义因传递给Emitter 参数包的每个类型而异。
我在 MinGW 上尝试了当前的方法,但收到这些错误消息,我有点迷茫:
/* Line: template < template <typename Ret, typename... Args> Signal< Ret (Args...) > ... Sig> */
main.cpp|15|error: expected 'class' before 'Signal'|
/* Line: template < template <typename Ret, typename... Args> Signal< Ret (Args...) > ... Sig> */
main.cpp|15|error: expected '>' before '<' token|
/* Line: class MyType : public Emitter<Signal_A, Signal_B, Signal_C> */
main.cpp|29|error: wrong number of template arguments (3, should be 1)|
/* Linne: class Emitter */
main.cpp|16|error: provided for 'template<template<class Ret, class ... Args> class Signal> class Emitter'|
如果有人能澄清这一点或提供可行的解决方案,我将不胜感激。
可用的编译器:MinGW GCC 4.9.2(也是 5.1.0)
【问题讨论】:
标签: templates c++11 inheritance filtering variadic