zoukankan      html  css  js  c++  java
  • 结构体函数指针成员与函数指针类型的结构体类型形参的相互嵌套定义及使用问题

    @2018-10-24

    结构体函数指针成员与函数指针类型的结构体类型形参的相互嵌套定义及使用问题

    具体代码

     1 #include <stdio.h>
     2 
     3 #define METHOD            0
     4 
     5 
     6 #if METHOD
     7 
     8 typedef void(*pf)(struct _struct *parameter);
     9 
    10 #else
    11 /* VC++6.0此法报错,gcc编译OK */
    12 struct _struct;
    13 typedef void(*pf)(struct _struct parameter);
    14 
    15 #endif
    16 
    17 
    18 struct _struct
    19 {
    20     int i;
    21     pf fun;
    22 };
    23 
    24 #if METHOD
    25 
    26 void testFun(struct _struct *parameter)
    27 {
    28     printf("这是一个函数指针与结构体定义的先后问题!
    ");
    29     printf("testObj.i = %d
    ", parameter->i);
    30 }
    31 
    32 #else
    33 
    34 void testFun(struct _struct parameter)
    35 {
    36     printf("这是一个函数指针与结构体定义的先后问题!
    ");
    37     printf("testObj.i = %d
    ", parameter.i);
    38 }
    39 
    40 #endif
    41 
    42 
    43 int main()
    44 {
    45     struct _struct testObj;
    46 
    47     testObj.i = 99;
    48     testObj.fun = testFun;
    49 
    50 #if METHOD
    51     testObj.fun(&testObj);
    52 #else
    53     testObj.fun(testObj);
    54 #endif
    55 }
  • 相关阅读:
    南阳1071
    hdu5110 dp
    hdu1199 线段树
    hdu5107 线段树
    hdu5106 数位dp
    hdu 5103 状态压缩dp
    C Strange Sorting
    hdu5102 枚举每条边的长度
    uva672
    uva473
  • 原文地址:https://www.cnblogs.com/skullboyer/p/9842287.html
Copyright © 2011-2022 走看看