I come from C# so having to manually manage memory is new to me.
I was wondering what happens if I have a class Foo that holds another object Bar and I instantiate foo on the heap; where does bar end up?
In code:
class Bar {
public:
Bar(){}
};
class Foo {
Foo()
: bar()
{
}
private:
Bar bar;
};
int main()
{
Foo* foo = new Foo();
delete foo;
return 0;
}
Is bar also placed on the heap? and in that case do I need to manually release bar or is it freed automatically by Foo?