Class members are part of a class instance. Where they live depends upon where the instance lives. If you declare an instance of a class as an automatic variable, then it is on the stack. If you allocate it with operator new, then it is on the heap. See example: … Read More
First, a bit of vocabulary. Given a class, an object of that class will contain data members and base-class objects (the instance of its base-classes), these two things are referred to as *sub-objects*.
So, the fundamental thing to understand here is that, from a memory perspective, an object and the … Read More
> Can functions even be on the heap?
Functions do not occupy any memory on a per-object basis, only the data members. Functions are made up of executable code and occupy memory on the code-section of the program's memory. They exist in one place for the whole program, and require … Read More
> I was reading some book and the author for some reason said that classes just store pointers to the location of all datamembers
That's the way it is in *reference-semantics* languages like Java or C#. This is not true for C++ (which has *value-semantics*), either the author is not … Read More