#include <stdio.h>
#include <malloc.h>

struct Hello{
    void (*sayHello)(char* name);
};

void sayHello(char* name){
    printf("hello, %s\n",name);
}

int main(){
    struct Hello* hello=(struct Hello *)malloc(sizeof(struct Hello));
    hello->sayHello=sayHello;//这个结构体有多少个函数,就要在这个有多少个结构体内,函数指针指向函数的声明。
    hello->sayHello("a");
    free(hello);

    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2021-07-13
  • 2021-08-10
  • 2023-02-24
  • 2021-09-02
猜你喜欢
  • 2023-02-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
相关资源
相似解决方案