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

#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. DAY03、基本数据类型和运算符

    一.基本数据类型的使用 1.整型int: 作用:用来记录年龄.等级.数量 定义:age=18 使用:数学运算与比较运算: 例:print(10>3) print(10/3) 2.浮点型float ...

  2. 如何在网页中用echarts图表插件做出静态呈现效果

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  3. python设计模式第九天【策略模式】

    1. 定义 对一系列算法进行封装,为所有算法定义一个抽象的算法接口,可以平滑的进行算法切换 2. 策略模式的UML图 3.代码实现 #!/usr/bin/env python #! _*_ codin ...

  4. ASP.NET MVC和Web API中的Angular2 - 第2部分

    下载源码 内容 第1部分:Visual Studio 2017中的Angular2设置,基本CRUD应用程序,第三方模态弹出控件 第2部分:使用Angular2管道进行过滤/搜索,全局错误处理,调试客 ...

  5. Jarvis OJ A Piece Of Cake

    看图片的隐写术自闭,本来想看一看jarvisoj 的basic放松一下心情,结果一道题就做了一晚上qwq 首先看到这道题的时候想到的是凯撒密码(这其实是Google之后才知道这个名字的)枚举了26种位 ...

  6. 实验吧 WEB 貌似有点难

    错误!你的IP不在允许列表之内! 提示:代码审计 这个提示可谓是非常良心了,一看源代码是一个识别ip地址的东西,如果IP为1.1.1.1那么就会得到KEY. 第一个if是判断是否有client-ip ...

  7. PHP——base64的图片的另类上传方法

    前言 这只是个暂行的办法,回头研究好七牛云的base64上传或者vue的文件上传后还是要进行更改的 想法是这样的,既然前端只能穿base64的那就传base64的然后转为文件上传到七牛云后再删除 本地 ...

  8. windows 下 mysql服务的注册和删除

    注册: mysqld --install 服务名 --defaults-file="C:\Mysql\mysql-5.7\my.ini" 删除 sc delete 服务名 停止服务 ...

  9. linux 定时任务到秒级

    linux crontab 只有到分钟级别的 有两种方法 方法1.写个sh脚本,循环(下例为每秒访问一次百度) #! /bin/bash PATH=/bin:/sbin:/usr/bin:/usr/l ...

  10. 【HDU-6148】 Valley Numer(数位dp)

    百度之星2017复赛1005 HDU-6148 Valley Numer 题意 不出现上升后直接下降数位的数,不超过n的有几个.前导零不算. 题解 dfs(当前数位的位置len,这位的数num,是否在 ...