Have the code:
struct FooBar
{
FooBar()
{
MyObject obj;
/// when c-tor is ended, obj must be deleted through d-tor call
}
};
...
FooBar* fooBar(new FooBar);
fooBar is allocated on the heap. But object MyObject obj inside FooBar‘s constructor does not know where it is created. So could be MyObject instantiation in the context of FooBar treated like it was created in the stack?
Does object allocated on the heap have its own stack? What is the size of such stack?
objis allocated on the stack in your example (the “ordinary” stack, the “same” that is used in the code that callsnew FooBar– assuming your environment has a stack to begin with).The fact that
thispoints to somewhere on the heap doesn’t change the fact that the constructor is a (relatively) ordinary function call, and uses the same stack as other functions.