为结构添加方法
程序代码:
#include <stdio.h> typedef void (*printDel)(); typedef struct point { int x; printDel print; }point; void print(point*); point* new_point(); point* new_point() { point* tmp=(point*)malloc(sizeof(point)); tmp->print=print; return tmp; } void print(point* tmp) { printf("%d",tmp->x); } int main(void) { point* xy=new_point(); xy->x=10; xy->print(xy); free(xy); getch(); return 0; }
想实现如此的:xy->print()不知有解决之道否?