当前位置:网站首页>Function and usage of function pointer

Function and usage of function pointer

2022-07-05 07:38:00 Code boy

1、 Function pointer function :
The advantage of using function pointers is that , Multiple modules that realize the same function can be identified together , This makes it easier
Easy for later maintenance , The system structure is clearer . Or summed up as : Easy to layer design 、 It's good for system abstraction 、 Reduce coupling and separate the interface from the implementation .

#include <iostream>
using namespace std;
int arr(int a, int b) {
     return 0; }
int brr(int a, int b) {
     return 1; }

int main()
{
    
	int (*frr)(int, int);// Here is the function pointer 
	frr = arr;// It can point to arr
	cout << frr(1, 2) << endl;
	frr = brr; You can also point to brr, Just change the object pointed to , You can operate different functions 
	cout << frr(1, 2) << endl;
	return 0;
}

C/C++ Function pointer Usage Summary :https://www.cnblogs.com/lvchaoshun/p/7806248.html

原网站

版权声明
本文为[Code boy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140552198566.html