zoukankan      html  css  js  c++  java
  • template specifiers not specified in declaration of ‘template<class Key> class hash’

    尝试写显示特化样例的时候,写了如下代码

    #include <iostream>
    #include <cstddef>
    
    using namespace std;
    
    #define __STL_TEMPLATE_NULL template<>
    
    template<class Key>
    class hash {
    public:
        void operator()() {
            cout << "Hash<T>" << endl;
        }
    };
    
    //explicit specialization
    __STL_TEMPLATE_NULL
    class hash<char> {//template specifiers not specified in declaration of ‘template<class Key> class hash’
    public:
        void operator()() {
            cout << "Hash<char" << endl;
        }
    };

    编译时 在红色注释处报错

    然后找原因半天找不到

    换种写法,出现以下错误

    C++::EC - expected initializer before '<' token

    根据别人的文章才知道有类名“hash“有混淆。

     解决方法:改一下名字,加个命名空间,或者去掉<cstddef>头文件应该就可以了

    少壮不识cpp,老大方知cpp可怕
  • 相关阅读:
    with
    网编
    选课新系统大作业
    网络编程

    知识点
    Python
    学生选课大作业
    理解position与anchorPoint[转]
    毛玻璃效果的简单使用
  • 原文地址:https://www.cnblogs.com/Jacket-K/p/9282773.html
Copyright © 2011-2022 走看看