C++ “X 不是模板”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6970219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 21:03:04  来源:igfitidea点击:

'X is not a template' error

c++templatesgcc

提问by jww

I'm having trouble declaring a template class. I've tried an number of ill-readable and non-sensical combinations.

我在声明模板类时遇到问题。我尝试了许多难以阅读和无意义的组​​合。

template <class C, class M >
class BlockCipherGenerator : public KeyGenerator
{
  ...
  private:
      M < C > m_cipher;
};

And

template <class C, class M >
class BlockCipherGenerator : public KeyGenerator
{
  typedef typename C::value_type CIPHER;
  typedef typename M::value_type MODE;
  private:
      MODE < CIPHER > m_cipher;
};

回答by Lightness Races in Orbit

It's what it says.

这就是它所说的。

Your template parameter list says that Mis a class, not a template.

您的模板参数列表说那M是 a class,而不是 atemplate

If you say that it's a class template, then everything's fine:

如果你说它是一个类模板那么一切都很好

template <class C, template <class C> class M>
class BlockCipherGenerator : public KeyGenerator
{
      M<C> m_cipher;
};


Remember, something like std::vectoris nota class, but a class template. Something like std::vector<int>is a class (type).

请记住,类似std::vector不是一个类,而是一个类模板。类似的东西std::vector<int>是一个类(类型)。