When I create a class with a class pointer, for example:
class A{
B* p_b1;
B* p_b2;
A(){}
}
I assume that the compiler creates space for at least 2 pointers to instance A. My question is if they are not pointers, but rather objects such as:
class A{
B b1;
B b2;
A(){}
}
Will the compiler allocate space for b1 and b2 in the memory space of class A? Or will he declare the actual classes B elsewhere on the stack?
The reason I'm asking about this is because I am trying to reduce the memory allocation in my code and wandered if that made any difference.
source
share