众所周知,c语言是一个面向对象的语言
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <stack>
//#include <unordered_map>
//#include <hash_map>
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define ull unsigned long long
#define uint unsigned int
using namespace std;
struct Demo {
int x, y;
void(*constructor)(Demo *This);
void(*member_function1)(Demo *This);
void(*member_function2)(Demo *This);
}*temp;
void member_function1(Demo *This) {
printf("fun1\n");
}
void member_function2(Demo *This) {
printf("fun2\n");
}
void construct(Demo *This) {
printf("construct\n");
This->constructor = construct;
This->member_function1 = member_function1;
This->member_function2 = member_function2;
}
#define TDemo(name) Demo name;construct(&name);
#define newDemo() (temp = (Demo*)malloc(sizeof(Demo)), construct(temp), temp)
int main() {
TDemo(temp1);
temp1.member_function1(&temp1);
temp1.member_function2(&temp1);
Demo* temp2 = newDemo();
temp2->member_function1(temp2);
return 0;
}