关于一个函数指针的问题?

来源:百度知道 编辑:UC知道 时间:2024/05/17 20:58:35
我用borland c++6.0运行下面这个程序
#include<iostream>
using namespace std;
void main()
{
int (*a)(int i,char *c)
{
cout<<i<<c<<endl;
}
(*a)(5,"lsjdlj");
}
出现了:
[C++ Error] Unit1.cpp(5): E2451 Undefined symbol 'a'
[C++ Error] Unit1.cpp(5): E2188 Expression syntax

#include<iostream>
using namespace std;
int a(int i,char *c)
{
cout<<i<<c<<endl;
return 0;
}
void main()
{
(*a)(5,"lsjdlj");
}
这样用

概念不清楚啊,看的什么书

函数指针是用来存放函数入口地址的,只是一个变量。函数要单独定义才行。

#include<iostream>
using namespace std;

int f(int i,char *c)
{
cout<<i<<c<<endl;

return 0;
}

void main()
{
int (*a)(int, char *) = f;

a(5,"lsjdlj");
}