【问题标题】:Specialization of template <class T> definition of template <class T>模板<class T>的特化模板<class T>的定义
【发布时间】:2014-03-20 10:25:47
【问题描述】:
namespace std {

    template <> 
    class hash<nGram>{
        public :
            size_t operator()( const nGram &k ) const
            {
                return k.m_hashval;
            }
    };
};

我知道我需要在某处添加一个命名空间。但是我不知道在哪里或如何。我对此很陌生。

错误消息:'template struct std::tr1::hash' 在不同命名空间中的特化 ?/?/gcc/V4.1.2/bin/../lib/gcc/sparc-sun-solaris2.10/4.1.2/../../../../include/c++/4.1.2 /tr1/functional1:1101: 错误:来自'template struct std:tr1::hash'的定义

【问题讨论】:

  • 一个是std::tr1,一个是std
  • 升级你的编译器
  • 我不能。这是学校的电脑

标签: c++


【解决方案1】:

在模板声明周围添加namespace tr1,但在 std 命名空间内。

【讨论】:

  • 所以把它像“namespace tr1{”放在std之后的行中。并让它在 std 结束之前结束?
  • 成功了!太感谢了。我已经用谷歌搜索了 2 个小时。
猜你喜欢
  • 2019-07-30
  • 1970-01-01
  • 1970-01-01
  • 2012-10-13
  • 2011-05-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-21
相关资源
最近更新 更多