Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 类的别名模板作为模板参数c++;_C++_Templates_Metaprogramming_Template Meta Programming - Fatal编程技术网

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>