作者:帅气zxc_925 | 来源:互联网 | 2023-05-17 14:22
#include
#include
#include
using namespace std;
//定义函数模板
template
void display_message(const string &msg, const vector &vec);
template
void display_message(const string &msg, const list <);
//函数指针使用
//函数指针,格式比较复杂,必须指明其所指函数的返回类型及参数列表。
//本例的参数列表内容是:int,返回类型是 const vector*
//此外,函数指针的定义必须将*放在某个位置,表示这份定义表示的是一个指针,然后加一个名称。
//注意,第三个参数初值给的是0,这是有目的的。
bool test(int pos, int &ele, const vector* (*seq)(int) = 0 )
{
//....
//赋予函数指针初值,如果初值为0,表示并未指向任何函数
if ( !seq )
{
printf("seq is null !!!");
}
//由函数指针指向的函数,其调用方式和一般函数相同
const vector *p = seq(pos);
return true;
}