c++模板使用来自基类的声明

标签 c++ templates c++11

<分区>

为什么以下代码不起作用(使用 VS2013)?

class Test1
{
public:
  template<typename T>
  using my_type = T;
};

template<typename T, typename V>
class My : public T
{
public:
  using t_type = T;
  using my_type2 = t_type::my_type<V>;
};

int main()
{
  const My<Test1, double>::my_type2 x = 5.5;

  return 0;
}

Test1::my_type 会有更复杂的类型。我将是一个基于策略的类,其中 Test1 将是策略之一。 my_type2 应该成为基于策略的特定类型。并且 Test1 不能是直接采用 V 类型的模板。谢谢。

最佳答案

欢迎来到 C++ 的黑暗角落

改变这个

using my_type2 = t_type::my_type<V>;

为此:

using my_type2 =  typename t_type::template my_type<V>;

关于c++模板使用来自基类的声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29748011/

相关文章:

c++ - 移动大型非指针基础对象的语义

c++ - 需要有关 c++ system() 函数的帮助

c++ - 使用异常抛出构造函数初始化对象的正确方法

javascript - Ember.js:内联 Handlebars 模板在应用程序的根元素处呈现

c++ - 具有跨 DLL/SO 使用的静态数据成员的模板类

c++ - 在 move 构造过程中,从对象 move 的基本类型成员的值可以说些什么?

c++ - int main(int, char const* const*) 格式正确吗?

c++ - 为自己启动成员变量启用编译器警告

c++ - "Expression: list iterators incompatible"在遍历列表期间随机发生

html - 链式 html 标记