Hi all.
I know that local variables are declared in the stack and static, global and variables allocated with new are allocated on the heap.
But where are allocated the members of this class for example :
class Dog {
int a;
int *b;
}
if it's created on the stack with Dog myDog; ? Where will be located a and where will be located b ?
And where will they be located, if the instance is created on the heap with new, i.e. Dog *myDog = new Dog();
Thank you
Patric
A class is simply a collection of its members. So wherever the class is allocated, that's where its members are allocated.
If you put Dog myDog;
on the stack, then myDog's members are on the stack. If you put it on the heap with new, then its members are on the heap.
Last edited on
I see. Thank you very much :) Have a nice day !