【发布时间】:2018-08-24 14:06:32
【问题描述】:
如何将作为模板参数给定的类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;
}
我尝试了几种解决方案,在语句中的每个可能位置添加 template 关键字(如 template<class T> typename _A::Container<T>、typename _A::template Container...),但 g++ 给出了 “模板参数 1 无效” 或 “类型/值不匹配”!
【问题讨论】:
标签: c++ templates metaprogramming template-meta-programming