C模拟实现类的功能

C语言的结构体加上函数指针来实现。函数

#include <stdio.h>; typedef struct {         int a;         char b;         int (*p)(int,char); } xhl; int test(int m_a,char m_b); int main() {         xhl m_s;         m_s.a=5;         m_s.b='w';         m_s.p=test;         (*m_s.p)(m_s.a,m_s.b);         return 0; } int test(int m_a,char m_b) {         printf("%d,%c\n",m_a,m_b);         return 0; }
相关文章
相关标签/搜索