#include <stdio.h> #ifndef C_Class #define C_Class struct #endif C_Class Rf { int power; void (*set_power)(C_Class Rf *p, int power); }; void set_power(C_Class Rf *p, int power) { p->power = power; } int main() { C_Class Rf rf_test; rf_test.set_power = set_power; // function pointer init rf_test.set_power(&rf_test, 5); printf("%d\n", rf_test.power); return 0; }
时间: 2024-11-05 15:58:11