C++函数指针的调用

来源:百度知道 编辑:UC知道 时间:2024/09/21 18:35:15
// 5.cpp : Defines the entry point for the console application.

//注意其中int (*cmp)(const char *,const char *)指针函数调用形式
#include "stdafx.h"
#include <iostream.h>
#include <string.h>
#include <stdio.h>

void fi(char *p1,char *p2,int (*cmp)(const char *,const char *));
void cp(char *p1,char *p2,int (*pc)(const char *,const char *));
void main()
{
char p3[80],p4[80];
gets(p3);
gets(p4);
int (*p)(const char *,const char *);
int (*q)(const char *,const char *);
p=strcmp;
q=strcat;
fi(p3,p4,p);
cp(p3,p4,q);
}
void fi(char *p1,char *p2,int (*cmp)(const char *,const char *))
{
cout<<"Testing if the two sentences are eaqual: ";
if(!cmp(p1,p2))
cout<<"eaqual"<<endl;
else
cout<<"unequal"<<endl;
}
void cp(char *p1,char *p2,int (*pc)(const

strcat的原型为char * strcat (char *s, const char *ct)
而您的声明q为int (*q)(const char *,const char *);

所以报错:不能将char *(__cdecl *)(char *,const char *)的函数转换为
'int (__cdecl *)(const char *,const char *)

int strcmp( const char *string1, const char *string2 );