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 }
  • 相关阅读:
    Alignment
    Matrix 二维树状数组的第二类应用
    网络请求中的URL中传bool型数据
    把推送证书给服务器
    完全取代VC上原有的view
    图层CALayer的使用
    数组使用的注意事项
    使用CocoaPods
    声明遵循协议
    神奇的navigationBar.translucent
  • 原文地址:https://www.cnblogs.com/skullboyer/p/9842287.html
Copyright © 2011-2022 走看看