I'm interested in the nuts and boltw of C++ and I wondered what actually changes when an object is instantiated. I'm particularly interested if the functions are then added to memory, if they are there from runtime or if they are never stored in memory at all.
If anyone could direct me to a good site on some of the core bolts of C and C++, I'd love that too.
Thanks, Jo
Not sure of a good web site, but Inside The C++ Object Model is a pretty good book.
At least in the usual case, the member functions exist completely independent of any instance of the class. Instead, an instance of the class is a struct containing the (non-static) data members of the object. If the class has at least on virtual function, the object will also contain a pointer to a vtable, which is basically an array of pointers to functions.
When a member function is called, the address of that object is passed as a hidden parameter to the function (many compilers reserve a register just for it) and in the function it's referred to as this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With