I just got a question regarding the storage of c++ class members.
For example, I have a class like this:
class MyClass1{
int a;
int b[4];
int c;
}
In the main function:
int main(){
MyClass1 class1;
MyClass1* class_ptr1= new MyClass1();
}
Then how are the members a,b,c stored? For class1, I think all members are allocated with a space in stack, even the array b.
Then what about class_ptr1? Apparently it's dynamically allocated, are the members dynamically allocated as well, even thought they are not pointers.
Thanks very much.
Thanks very much for the replies. Now I understand that once the class is dynamically allocated, all its members are also dynamically allocated. In that case, do I need to do anything to deallocate them, once I finished using the class? I mean, is it fine just to:
delete(class_ptr1);
or I need to free its members first.