在可变参数模板类中定义的不同类型

时间:2015-09-02 02:00:50

标签: templates overloading variadic

我正在尝试允许这些类的不同用户通过Monitor将不同的配置传递给DoerT。如果有人想使用“myU”他们可以,如果没有,他们不会被迫通过。然后我想专门为这个特定的NYConfig设计DoerT的成员函数。有几个“主线”使这成为可能。我收到了编译错误:EX:

Config.H

#include "Doer.H"

template<class T>
struct ConfigT
{
     typedef T myT;
     typedef DoerT<ConfigT> Doer;
};

template<class T, class U>
struct NYConfig
{
   typedef T myT;
   typedef U myU;
   typedef DoerT<NYConfig> Doer;
};




Monitor.H

#include "Config.H"
#include "Doer.H"

template<typename ...monitors>
struct Monitor;

template<class T>
struct Monitor<T>
{
   typedef ConfigT<T> Config;
   typedef DoerT<Config> Doer;
};

template<class T, class U>
struct Monitor<T,U>
{
  typedef NYConfig<T,U> Config;
  typedef DoerT<Config> Doer;
};


Doer.H

#include "Config.H"

template<class ConfigT>
class DoerT
{
    bool start();

};

template<class ConfigT>
bool DoerT<ConfigT>::start() {....}

//error is here:
//error 'NYConfig' was not declared in this scope.
//I've also tried <NYConfig<myT,myU> >::start
template<>
bool DoerT<NYConfig>::start() 
{
     if(NYConfig::u == "yes")
         return true;

     return false;
}




Main1.C

struct myT {int t; };
struct myU {std::string u};

typedef Monitor<myT,myU> monitor;
typedef monitor::Config Config;
static monitor m;

Main2.C
struct myT2 {int t2; }
typedef Monitor<myT2> monitor;
typedef monitor::Config Config;
static monitor m;

0 个答案:

没有答案