C++ 类的别名模板作为模板参数c++;
如何将类C++ 类的别名模板作为模板参数c++;,c++,templates,metaprogramming,template-meta-programming,C++,Templates,Metaprogramming,Template Meta Programming,如何将类a的别名模板作为模板参数指定给从模板基类B继承的类C #include <vector> struct A { // the alias template I want to refer to: template<class T> using Container = std::vector<T>; }; // the base class template<template<class> class _Co
a
的别名模板作为模板参数指定给从模板基类B
继承的类C
#include <vector>
struct A
{
// the alias template I want to refer to:
template<class T>
using Container = std::vector<T>;
};
// the base class
template<template<class> class _Container>
struct B
{
_Container<int> m_container;
};
template<class _A>
struct C : public B< typename _A::Container >
{// ^^^^^^^^^^^^^^^^^^^^^^
};
int main()
{
C<A> foo;
}
#包括
结构A
{
//我要参考的别名模板:
样板
使用Container=std::vector;
};
//基层
样板
结构B
{
_集装箱m_集装箱;
};
样板
结构C:public B
{// ^^^^^^^^^^^^^^^^^^^^^^
};
int main()
{
C foo;
}
我尝试了几种解决方案,在语句中的每个可能位置添加
template
关键字(比如template typename\u A::Container
,typename\u A::template Container
),但是g++
给出了“模板参数1无效”或“类型/值不匹配” 正确的语法应该是:
template <class A>
struct C : public B< A::template Container >
{
};
模板
结构C:公共B
{
};
:不要使用<代码> < A >代码>模板参数的名称,在C++中保留。< /P>