I wanted to make an object oriented preprocessor to my programming language which converts my language into C (like early C++). And I want to simulate the classes with structures. And the question is: how can I declare a variable inside a struct like this:
typedef struct { //equivalent of class
int a = 5;
int (*sub)(int) = &int_sub; //function of a class, uses an external declared function
} class_name;
I tried the code above but the compiler wrote this:
error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token
void (*sub)(int) = &int_sub;
I have two questions:
Can I declare a variable inside a struct?
If yes, how?