CppQuiz系列 1
来源:互联网 发布:淘宝 css 显示代码 编辑:程序博客网 时间:2024/06/03 16:43
本系列是CppQuiz 的题解的中文翻译,在被虐无数次后终于通关,CppQuiz主要关注c++11中容易出错的一些点,比较坑,也比较烧脑。
keywords : 模板,参数匹配
#include <iostream>template <class T> void f(T &i) { std::cout << 1; }template <> void f(const int &i) { std::cout << 2; }int main() { int i = 42; f(i);}
模板实例化时会实例化为void f(int &)
,和特化的模板void f(const int &)
更为匹配,如果改成const int i=42;
就会输出2。
The templated function will be instantiated as void f(int&)
, which is a better match than f(const int&)
.
好,问题来了,改成f(42)
会发生什么?
答案是:CE(compilation error),至于为什么,将在下一期解析。
0 0
- CppQuiz系列 1
- CppQuiz系列 2
- CppQuiz 系列3
- NetSNS二次开发系列1--文章系列简介
- MEF学习系列笔记系列(1)
- StrutsCatalog系列(1)--BaseAction
- struts2系列之1
- 考研系列1
- GeoRSS 学习系列(1)
- MACD系列1
- ORACLE 入门系列(1)
- Learning python 系列1
- ajax系列教程(1)
- Microwindow系列(1)--移植
- [SilkyBible] XviD系列-1
- XNA系列(1)
- s3c2440学习系列1
- BEA WebLogic系列[1]
- 线程
- Linux批量添加用户
- SIA实战(三):为bean动态的增加新方法
- HDU - 3652 数位dp水题
- 2017.02.14总结
- CppQuiz系列 1
- maven POM.xml 标签详解
- matlab 中的 figure 之间的切换方式
- mysql之数据约束
- Android Lint常见问题分析(for studio)
- Oracle执行计划基础详解(转载)
- PAT-B1037. 在霍格沃茨找零钱
- C语言用函数指针的数组简单实现计算器功能
- 《MySQL必知必会》学习笔记十一(操作表)------掌握部分