Where are the functions inside of structs stored in memory?

Viewed 174

Let's say I have a struct like this:

struct 64BitStruct
{
    uint64_t value;
    void SomeFunction(bool enable);
    bool SomeOtherFunction();
};

sizeof(64BitStruct) returns 8 bytes, which is 64 bits. I assume those 64bits are the value variable in the struct, but then where are the functions stored?

1 Answers

Member functions are common functions of all objects of the structure type. So they are stored separately from objects. The size of the structure in your example is in fact the size of its data member. If a structure has virtual functions then it implicitly includes a pointer to the table of virtual function pointers as a data member for each object of the structure type.

Related