C++ 模板参数

C++ 模板参数,c++,visual-studio-2008,templates,visual-c++,C++,Visual Studio 2008,Templates,Visual C++,我有ClassA和ClassB。现在我想使用ClassC,它有公共的ARG\u类型,并提到类作为模板参数 ClassC很简单 但是是否可以声明ClassC,以便A和B类都知道使用ARG_类型作为其模板参数?是的,可以通过使用“模板参数”来完成 声明ClassC如下: template<typename Arg, template<typename T_Arg> class T_ClassA, template<typename T_Arg> cl

我有
ClassA
ClassB
。现在我想使用
ClassC
,它有公共的
ARG\u类型
,并提到类作为模板参数

ClassC
很简单


但是是否可以声明
ClassC
,以便A和B类都知道使用ARG_类型作为其模板参数?

是的,可以通过使用“模板参数”来完成

声明ClassC如下:

template<typename Arg, 
    template<typename T_Arg> class T_ClassA, 
    template<typename T_Arg> class T_ClassB>
class ClassC
{
   typedef T_ClassA<Arg> MyClassA;
   typedef T_ClassB<Arg> MyClassB;

   // Use MyClassA and MyClassB
}; 
模板
C类
{
typedef T_ClassA MyClassA;
typedef T_ClassB MyClassB;
//使用MyClassA和MyClassB
}; 
使用

ClassC

它应该可以正常工作。

这是可以做到的,但是我不太喜欢这个解决方案

问题是,假设我定义:

template <class Arg, class Policy> class Polymorph;
如果您没有可用的C++0x,请避免使用它,并重新使用STL方式,即使它更详细

template <class Arg, class Policy> class Polymorph;
template <class Arg, template <class> class ClassA>
struct MyTemplate
{
  typedef ClassA<Arg> classA_type;
};

template <class Arg, class Policy> class Polymorph;

// C++0x required for following declaration
template <class Arg>
typedef Polymorph<Arg, ConservativePolicy> ConservativePolymorph;

typedef MyTemplate<int, ConservativePolymorph> MyTemplateC;