Hi
I just started with c++ and I'm a little bit confused where stuff
go...
Assume we have a class:
class test {
private:
int arr[100];
};
That is, I assume that 'arr' is allocated on the stack, since I don't
use new.
But where is this array allocated if I allocate a test object in the
heap?
I.e.
test t = new test;
The object will reside in the heap so therefore the 'arr' will be in
the heap too?
Are there any pro/cons to heap/stack allocate member variables (of non
trivial type)?
Thanks
Jonas
I just started with c++ and I'm a little bit confused where stuff
go...
Assume we have a class:
class test {
private:
int arr[100];
};
That is, I assume that 'arr' is allocated on the stack, since I don't
use new.
But where is this array allocated if I allocate a test object in the
heap?
I.e.
test t = new test;
The object will reside in the heap so therefore the 'arr' will be in
the heap too?
Are there any pro/cons to heap/stack allocate member variables (of non
trivial type)?
Thanks
Jonas
Comment