5.1 Memory Models for Classes

To understand how memory models apply to classes, it's necessary to know how objects are represented in memory.

Summary: Member functions are stored once for the entire class.

Each object contains its own copy of the data members defined for its class (except for the static members). However, an object does not contain its own copy of the code for the member functions. Member functions are stored only once for the entire class.

When you call a member function of a particular object, the address of that object is passed to that function as a hidden argument.

For example, this statement in C++

myWindow.resize();

is analogous to the C statement

resize( &myWindow );

The member function implicitly uses the address to access the object's data members. That address is available from inside the member functions as the this pointer.