Question Summarized:
I'm well aware how when you enter a new scope, variables get "added onto the stack" but I guess my question is how exactly are objects represented on the stack on a lower-level?
How are an object's member variables represented? Is an object represented as just a literal sequential set of member variables added? What about if a member variable is a whole other object?
What about member functions? Are they just an address to the function? So we add a pointer to the function definition? How does the system go from that to execution if it's called?
Example:
Let's say I have a class defined as follows:
class MyClass {
int a; // Primitive data member
double b; // Primitive data member
std::unordered_map<int, int>* some_map; // A pointer to an object
SomeOtherClass sub_obj; // Another object as a data member
void DoSomething() {
// some code ...
}
};
void function(const MyClass& obj) {
// Run some operations on obj
}
And I call function
, and obj
is added to the stack. What is "stacked" exactly?
PS Linking any resources for further reading about this nitty-gritty kind of thing would be much appreciated!