1. 程式人生 > >Go/函式/函式型別

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()
}