📄 main.cpp
字号:
#include <iostream>
#include <string>
using namespace std;
void t1(){cout<<"test1"<<endl;}
void t2(){cout<<"test2"<<endl;}
void t3(){cout<<"test3"<<endl;}
//void (*q)();
void main(int argc,char* argv[])
{
void * a[]={t1,t2,t3};
cout<<"比较t1()的内存地址和数组a[0]所存储的地址是否一致"<<t1<<"|"<<a[0]<<endl;
// cout<<a[0]();//错误!指针数组是不能利用数组下标操作调用函数的
typedef void (*fp)();//自定义一个函数指针类型
fp b[]={t1,t2,t3}; //利用自定义类型fp把b[]定义趁一个指向函数的指针数组
fp q;
void *p;
// q=a[0];
void *x;
x=&a[0];
if(t1 == a[0])
cout<<"yes"<<endl;
// q();
// a[2]();
//q=a;
b[1];//=0x0040117c;
b[0]();//现在利用指向函数的指针数组进行下标操作就可以进行函数的间接调用了;
b[1]();
cin.get();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -