struct class_t;
typedef struct class_t class_t;;
typedef struct data {
int i;
class_t * class;
} data;
struct class_t
{
int (* print)(const char *, ...);
};
class_t funclass = {printf};
int main(void)
{
data a;
a.class = &funclass;
a.i = 10;
a.class->print("%d", a.i);
getchar();
return 0;
}
----------------解决方案--------------------------------------------------------
LS解释一下代码好吗。。那个指针型函数的调用应该是(*pf)()这种形式的吧。。为什么可以直接调用呢。
----------------解决方案--------------------------------------------------------
#include <stdio.h>
struct class_t;
typedef struct class_t class_t;
typedef struct data {
int i;
} data;
int (* print)(const char *, ...);
int _tmain(int argc, _TCHAR* argv[])
{
data a;
a.i = 10;
print=printf;
(*print)("%d\n", a.i);
print("%d\n", a.i);
getchar();
return 0;
}
这两个都是对的
----------------解决方案--------------------------------------------------------