(C++) I find it a bit troublesome to managing elegantly memory in the following scenario:
I have a class named A, that has a member of class B. class B has pointer member to class C :
class C{}
class B{
C* c;
}
class A{
B b;
}
in class A's constructor, I initialized class B by passing it a pointer to object of class C I just created.
now, in the destructor of A, I want to free the object of class C I passed to B.
all of the options I know to do that just look for me not very elegant:
make C public in B so I can just do: "delete(b.c);" create a getter of the c pointer inside B and then do: "delete(b.Getblabla())" save the pointer I passed as a member of A and then release it: "delete(pointer_to_c)"
do you have some elegant offers?
edit: hey some clarifications, the reason why A allocates C and passing it to B is that C is an interface and I want B to be initialized with different implementations of C depends in the situation.