effective stl读书笔记 —— Item 6
来源:互联网 发布:ie浏览器淘宝登录不了 编辑:程序博客网 时间:2024/05/21 19:49
Item 6(当心C++编译器最烦人的分析机制)
几种声明函数的方式:
int f (double d);
int f (double (d)); //同上;d两边的括号被忽略
int f (double);//同上;参数名被忽略
int g (double (*pf) ());//g以指向函数的指针为参数
int g (double pf ());//同上;pf为隐式指针
int g (double ());//同上;省去参数名
c++的声明函数与对象的二异性:
class Widget {…}; //Widget类
Widget w(); //此处不会调用Widget默认构造函数,而是把w看成是返回Widget对象的函数//的声明
list<int> data (istream_interator<int> (dataFile), istream_iterator<int>()); //此处同上
解决方法:
(1) 把形参的声明用括号括起来是非法的,但给函数参数加上括号却是合法的,所以可以通过增加一对括号强制编译器按我们的方法工作(在有些编译器下可能不能编译通过):
List<int> data ( ( istream_iterator<int> (dataFile) ), istream_iterator<int>() );
(2) 避免使用匿名对象
istream_iterator<int> dataBegin(dataFile);
istream_iterator<int> dataEnd;
list<int> data(dataBegin, dataEnd);- effective stl读书笔记 —— Item 6
- effective stl读书笔记 —— Item 19
- effective stl读书笔记 —— Item 1
- effective stl读书笔记 —— Item 2
- effective stl读书笔记 —— Item 3
- effective stl读书笔记 —— Item 4
- effective stl读书笔记 —— Item 5
- effective stl读书笔记 -- Item 6
- 《Effective STL》读书笔记四:Item 6 - 9
- effective stl item 6
- Effective STL 读书笔记 6
- effective STL 读书笔记——第一章:容器
- 《Effective STL》读书笔记五:Item 10 - 11:关于allocator
- effective STL 读书笔记——第二章:vector和string
- effective STL 读书笔记——第三章:关联容器
- effective STL 读书笔记——第四章:迭代器
- effective STL 读书笔记——第五章:算法
- 《Effective STL》读书笔记六:Item 12:对 STL容器的线程安全性抱有现实的期望
- 一个好用的中文编码过滤器的代码
- 文件上传组件
- 使用Spring的mappingDirectoryLocations来配置Hibernate映射文件
- 如何使用 .net 的TreeView控件
- effective stl读书笔记 —— Item 5
- effective stl读书笔记 —— Item 6
- LS文法构图算法(1) 简介
- Spring使用Jndi时的一点说明
- 命令行执行编译
- PetShop分析
- 几个匪夷所思的成人寓言
- 关于ID和类名
- 搬回老家了
- Files Created by Visual C++