I had been getting myself confused on a few concepts lately, so I wanted to be sure I know the proper way to answer these questions, here is what I got
class Bar
{
// stuff here
};
class Foo
{
private:
Bar* bar;
Bar* arr;
public:
void setBar(Bar*);
void setArr(Bar*, int);
Foo();
};
Foo::Foo()
{
arr = new Bar[10];
}
void Foo::setBar(Bar* bar)
{
this->bar = bar;
}
void Foo::setArr(Bar* bar, int element)
{
// i did not test this to see if it worked so if i have incorrect syntax, im meaning to have an allocated array of Bar pointer objects
this->arr[element] = bar;
}
int main()
{
Foo foo();
Bar* bar = new Bar();
foo.setBar(bar);
Bar* bar2 = new Bar();
foo.setArr(bar2, 4);
}
1) If I do this command in main, "delete bar", does it delete the reference to bar inside the foo class ?
2) same goes for "delete bar2" does it delete the reference to bar object inside the allcoated array inside the foo class ?
3) sInce i declared Foo as Foo foo() instead of Foo* foo = new Foo(), since it is not an allocated object, i cant delete it(far as I know), so can any of the references within the class ever go out of scope ?
4) I think i may have gotton the wrong syntax since I did this on notepad, how could I assign an allocated array of Bar objects, of Bar pointers ? so each array element of arr is a Bar* that I can delete later in the deconstructor
5) lets say I did do Foo* foo = new Foo();, if i delete foo, im guess the references remain unless I take care of them in constructor?
I think that is all the questions I had left, I just needed some clarification, thanks in advance guys and gals!