C++ 有没有办法决定模板类的模板参数类型?

C++ 有没有办法决定模板类的模板参数类型?,c++,templates,C++,Templates,我有两个模板类,它们的参数由软件的不同层决定。 我必须在底层使用的类是 template <class RoutineInfoId, class ErrorInfoId, class LoadBarInfoId> class InformCBSet 模板 类InformCBSet 我必须在上层使用的类是 template <class LanguageId, class RoutineInfoId,

我有两个模板类,它们的参数由软件的不同层决定。 我必须在底层使用的类是

template <class RoutineInfoId, 
         class ErrorInfoId, 
         class LoadBarInfoId>
class InformCBSet
模板
类InformCBSet
我必须在上层使用的类是

template <class LanguageId,
          class RoutineInfoId, 
          class ErrorInfoId, 
          class LoadBarInfoId>
class Info
模板
班级信息
我还可以创建“Info”类

template <class LanguageId,
          class SomeInformCBSet>
模板
鉴于

typedef InformCBSet<SomeRoutineInfoId,
                    SomeErrorInfoId,
                    SomeLoadBarInfoId> SomeInformCBSet
typedef InformCBSet SomeInformCBSet
我想直接使用SomeInfoCBSet作为'Info class'的模板参数,从上层的SomeInfoCBSet中获取(即下层类的类型)

有没有办法实现这一点?
谢谢你可以用这个或类似的东西:

template<typename T> struct InformCBSetTypes;
template<typename T0, typename T1, typename T2>
struct InformCBSetTypes<InformCBSet<T0, T1, T2> > {
  typedef T0 RoutineInfoId;
  typedef T1 ErrorInfoId;
  typedef T2 LoadBarInfoId;
};

您可以使用另一个模板作为辅助对象来生成所需的类型:

// Helper accepts two types: a language ID and an InformCBSet instantiation. This
// declares the base template, but we need to specialize it, so there is no base
// template implementation.
template <typename, typename>
struct InformCBSet_to_Info;

// Specialization where the second argument is an InformCBSet instantiation.
template <typename LanguageId,
          typename RoutineInfoId, 
          typename ErrorInfoId, 
          typename LoadBarInfoId>
struct InformCBSet_to_Info<LanguageId, InformCBSet<RoutineInfoId,
                                                   ErrorInfoId,
                                                   LoadBarInfoId>>
{
    typedef Info<LanguageId,
                 RoutineInfoId,
                 ErrorInfoId,
                 LoadBarInfoId> info_type;
};

typedef InformCBSet<SomeRoutineInfoId,
                    SomeErrorInfoId,
                    SomeLoadBarInfoId> SomeInformCBSet;

typedef InformCBSet_to_Info<SomeLanguageId, SomeInformCBSet>::info_type SomeInfoType;
//Helper接受两种类型:语言ID和InformCBSet实例化。这
//声明基模板,但我们需要专门化它,因此没有基模板
//模板实现。
模板
结构信息设置为信息;
//专门化,其中第二个参数是InformCBSet实例化。
模板
结构信息设置到信息
{
类型定义信息类型;
};
typedef InformCBSet SomeInformCBSet;
typedef InformCBSet_to_Info::Info_type SomeInfoType;

我无法理解你的问题。是否要从模板专用化检索模板参数?像接收
Foo
和检索
A
B
C
?是的,昆汀。确切地
// Helper accepts two types: a language ID and an InformCBSet instantiation. This
// declares the base template, but we need to specialize it, so there is no base
// template implementation.
template <typename, typename>
struct InformCBSet_to_Info;

// Specialization where the second argument is an InformCBSet instantiation.
template <typename LanguageId,
          typename RoutineInfoId, 
          typename ErrorInfoId, 
          typename LoadBarInfoId>
struct InformCBSet_to_Info<LanguageId, InformCBSet<RoutineInfoId,
                                                   ErrorInfoId,
                                                   LoadBarInfoId>>
{
    typedef Info<LanguageId,
                 RoutineInfoId,
                 ErrorInfoId,
                 LoadBarInfoId> info_type;
};

typedef InformCBSet<SomeRoutineInfoId,
                    SomeErrorInfoId,
                    SomeLoadBarInfoId> SomeInformCBSet;

typedef InformCBSet_to_Info<SomeLanguageId, SomeInformCBSet>::info_type SomeInfoType;