Will heap allocated objects have their members allocated on the stack?
<p>Let's consider this example.</p>

<pre><code>class StaticlyManagedObject
{
   //some class members....
}
class DynamiclyManagedObject
{
   StaticlyManagedObject _staticlyManagedObject; //is this still allocated at the stack?

}

class Foo
{
  DynamiclyManagedObject * _dynamiclyManagedObject; //will be allocated in the heap.
  Foo()
  {
      _dynamiclyManagedObject = new DynamiclyManagedObject();
  }
}
</code></pre>

<p>I have been told that when we don't use dynamic memory management in C++, things are allocated in stack and we don't need memory management.</p>

<p>However, in this example. we have a dynamically allocated object which is called DynamiclyManagedObject I instantiate this object within the Foo constructor. My question is what happens to the statically managed data member of the DynamiclyManagedObject?</p>

<p>Is it still created on the stack or.. because of the fact that DynamiclyManagedObject created in the heap, every data member of it ends up into the heap.</p>