首页 > 代码库 > C模拟C++的类

C模拟C++的类

#include <stdio.h>#ifndef C_Class#define C_Class struct#endifC_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;}

 

C模拟C++的类