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

#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>头文件应该就可以了

template specifiers not specified in declaration of ‘template<class Key> class hash’的更多相关文章

  1. Template within template: why “`>>' should be `> >' within a nested template argument list” 解决方法

    如果直接这样写: std::vector<boost::shared_ptr<int>> intvec; gcc编译器会把">>"当成opera ...

  2. 模板(Template)

    最近阅读google chromium base container stack_container代码,深刻感觉到基础知识不扎实. // Casts the buffer in its right ...

  3. How to organize the Template Files in C++

    Normally you put class definitions in a header file and method definitions in a source file. Code th ...

  4. C++ Knowledge series Template & Class

    Function Function is composed of name, parameter (operand, type of operand), return value, body with ...

  5. Package template (html/template) ... Types HTML, JS, URL, and others from content.go can carry safe content that is exempted from escaping. ... (*Template) Funcs ..

    https://godoc.org/text/template GoDoc Home About Go: text/templateIndex | Examples | Files | Directo ...

  6. C++对象模型——Template中的名称决议方式 (第七章)

    Template中的名称决议方式 (Name Resolution within a Template) 必须可以区分下面两种意义,一种是C++ Standard所谓的"sope of th ...

  7. 关于template 的23个问题

    发现新大陆.曾经慢慢才知道的东西.原来有个集中营: 看看updated, 处理方式是这么的好 35.1 " id="link-to-faq-35_1" style=&qu ...

  8. C++ Templates (2.1 类模板Stack的实现 Implementation of Class Template Stack)

    返回完整目录 目录 2.1 类模板Stack的实现 Implementation of Class Template Stack 2.1.1 声明类模板 Declaration of Class Te ...

  9. C++(VS2015)模板显式特化之template语法深入理解

    首先说下遇到的情况: 这里在vc++6.0上建立了一个自定义模板类,再去覆盖这个类,分别使用部分覆盖,整体覆盖 但在vs2015上去整体覆盖类会报错. 错误如下: 错误原因:个人感觉是新版本的vs更接 ...

随机推荐

  1. django celery redis 定时任务

    0.目的 在开发项目中,经常有一些操作时间比较长(生产环境中超过了nginx的timeout时间),或者是间隔一段时间就要执行的任务. 在这种情况下,使用celery就是一个很好的选择.   cele ...

  2. Javascript 实现复制(Copy)动作方法大全

    一.实现点击按钮,复制文本框中的的内容 <script type="text/javascript"> function copyUrl2() { var Url2=d ...

  3. Microsoft Azure Tutorial: Build your first movie inventory web app with just a few lines of code

    Editor’s Note: The following is a guest post from Mustafa Mahmutović, a Microsoft Student Partner wh ...

  4. Nginx 减少磁盘读写次数

    L:133

  5. 读取jar文件的sha1码,请求maven官方的solrsearch接口查询该jar文件所对应的maven坐标信息

    版权声明:本文为博主原创文章,未经博主允许不得转载. import com.google.gson.JsonObject; import com.google.gson.JsonParser; imp ...

  6. maven加载本地jar包到repository

    maven加载本地jar到repository 这是一个常见场景,此处以本地opencv jar文件导入repository为例 1.Ubuntu下 mvn install:install-file ...

  7. 用随机投掷飞镖法计算Pi值(Randomness Throwing dart Pi Python)

    画一个边长为r的正方形和半径为r的四分之一的圆(如下图所示),向上面随机投掷飞镖,通过计算落在星星区域和整体区域的飞镖比例,即可求出π值. 公式推导如下: 假设正方形的边长r为1,那么飞镖落在星星区域 ...

  8. Unnitest测试框架总结

    Unnitest总结 第一点,setUp和tearDown方法 l  每次执行test开头的用例都会执行setUp和tearDown方法 l  如:  import unittest class M ...

  9. 【XSY2808】董先生的休闲方案 组合数学

    题目描述 有\(n\)个方案,编号为\(1\ldots n\). 最开始你不知道每个方案的编号. 你要按顺序提出这些方案. 每一个时刻你要做以下事情: 如果你阅读过下一个方案,就提出这个方案. 否则随 ...

  10. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) A - D2

    A. Be Positive 链接:http://codeforces.com/contest/1130/problem/A 题意: 给一段序列,这段序列每个数都除一个d(−1e3≤d≤1e3)除完后 ...