Chinaunix首页 | 论坛 | 博客
  • 博客访问: 39538
  • 博文数量: 10
  • 博客积分: 234
  • 博客等级: 二等列兵
  • 技术积分: 115
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-17 16:16
文章分类

全部博文(10)

文章存档

2011年(10)

我的朋友
最近访客

分类: C/C++

2011-03-21 00:36:33


#include
#include
typedef int int_m ;
int test(void);
typedef int (* pFunc)(void);
int main()
{
int_m a;
a =10;
printf("this a test %d \n",a);
printf("***********more*******\n");
pFunc t;
t = test;
t();
return 0;
}
int test(void)
{
        printf("typedef used in callback function...\n");
        return 0;
}

一个简单的例子,做个笔记。
加上回调,呵呵。
#include
#include

struct animal {
char name[24];
void (*cry)(struct animal *);
};


void cat_cry(struct animal * any)
{
printf("%s --%s",any->name,"miaomiao\n");
}

void dog_cry(struct animal * any)
{
printf("%s --%s",any->name,"wangwang\n");
}
int main()
{
//cat
   struct animal cat = {
.name = "cat",
.cry  = cat_cry,
};
struct animal * pcat = &cat;
pcat->cry(pcat);


//dog
struct animal dog = {
.name = "dog",
.cry = dog_cry,
};
struct animal * pdog = &dog;
pdog->cry(pdog);
return 0;
}




阅读(2121) | 评论(4) | 转发(1) |
给主人留下些什么吧!~~

吴秦2011-03-21 19:36:40

根本就没有用到所谓的callback

riribi2011-03-21 18:58:19

lxsyd2011-03-21 16:32:40

你这里好像没有callback,哈哈。

majia19842011-03-21 16:03:19

我晕,函数指针!