结构体与函数指针的特殊应用

#include <iostream>

using namespace std;


void print(int);

typedef struct
{
void (*print)(int num);
}TEST, *PTEST;

int main()
{
TEST test;
test.print = print;
test.print(10);


TEST test2 = {print};
test2.print(20);


return 0;
}

void print(int num)
{
cout << num << endl;
}

posted @ 2012-05-31 10:29  hanyuanbo  阅读(170)  评论(0编辑  收藏  举报