c++ primer阅读笔记

具有函数类型的形参所对应的实参将被自动转换为指向相应函数类型的指针。但是,当返回的是函数时,同样的转换操作则无法实现:

1 // func is a function type, not a pointer to function!
2 typedef int func(int*, int);
3 void f1(func); // ok: f1 has a parameter of function type
4 func f2(int); // error: f2 has a return type of function type
5 func *f3(int); // ok: f3 returns a pointer to function type

指向重载函数的指针,C++ 语言允许使用函数指针指向重载的函数:指针的类型必须与重载函数的一个版本精确匹配。如果没有精确匹配的函数,则对该指针的初始化或赋值都将导致编译错误:

1 extern void ff(vector<double>);
2 extern void ff(unsigned int);
3 // which function does pf1 refer to?
4 void (*pf1)(unsigned int) = &ff; // ff(unsigned)

 第八章标准 IO 库

posted @ 2013-05-02 09:09  xlhuang  阅读(105)  评论(0编辑  收藏  举报