typedef

typedef void (*IntegralFunc)(const uchar* src, size_t srcstep, uchar* sum, size_t sumstep,
                             uchar* sqsum, size_t sqsumstep, uchar* tilted, size_t tstep,
                             Size size, int cn );
一旦如此,就可以使用IntegralFunc去定义了。如IntegralFunc func;
 
直接看一段代码

typedef int (* func)(int ,int ) ;
 
int add(int a,int b)
{return (a+b);}
 
void main()
{
func f = add;//这里用法很像结构体,所以会导致读代码中的迷惑。
int n = f(1,2);
cout << n << endl;
}
其实,这里经过typedef定义的func是一种自定义函数指针类型,所以可以用来定义fun f,而这种类型是带两个参数,返回值是int的指向函数的指针。
posted @ 2013-02-24 13:10  yurius  阅读(145)  评论(0编辑  收藏  举报