why should declare these? I know for common c method, there is no need to declare, instead of it just define it:
In C there is no method, but only an attribute of the structure, which can be a Pointeur function, and then associated with the address of the function.
In addition, you must declare it in the class definition for the same reason as you, in C:
The compiler will change this preliminary declaration into a pointer function, and then associate this method with the construction of your object.
If a C ++ class definition needs to be converted to a C structure, the code will look like this:
struct Aclass { void (*Amethode))(int); } void Amethode(int) { return (0); } Aclass primaryObject = {&Amethode}; Aclass* AclassConstructor() { Aclass* object; object = malloc(sizeof(Aclass)); memcpy(object, primaryObject, sizeof(Aclass)); return (object); }
source share