Go/函数/函数类型

## 函数作为一种数据类型

package main

/*
	#include <stdio.h>
	typedef int (*FuncType_C)(int,int);		//c语言 函数类型
	int test_C(int a,int b){
		return a+b;
	}
	FuncType_C f_C = test_C;
	void test2_C(){
		int c = f_C(1,2);
		printf("%d\n",c);
	}
*/
import "C"

import "fmt"

type FuncType func (int, int) int			//go语言 函数类型

func test(a int, b int) int{
	return a+b;
}

func main() {
	var f FuncType
	f = test
	c := f(1,2)
	fmt.Println(c)
	C.test2_C()
}


猜你喜欢

转载自blog.csdn.net/qq_24243483/article/details/84037587