So I was playing with C++ features and I found that there is a big difference between C-style function pointers and C++ methods. Here is what do I mean:
typedef struct _myStruct {
void (*myFunctionOne)();
void(*myFunctionTwo)();
void(*myFunctionThree)();
} myStruct;
Size is 3 * 4 = 12 bytes.
typedef struct _emptyStruct {
} emptyStruct;
Size is 1 byte.
class myClass {
void myMethodOne();
void myMethodTwo();
void myMethodThree();
};
Size is 1 byte, like this is an empty struct.
Why is it empty? If C++ methods are not function pointers, how do they are implemented? How does class "know" about it's methods, if it doesn't have any pointers? This question doesn't actually distrubs me a lot, but it arouses my curiosity.