I have a doubt about how to keep a class... probably it is extremely simple to solve
This is the story:
- A class (A) has to keep a copy of other class (B)
- A can keep:
-- Case 1. a pointer to an instance of B created with new() by A
-- Case 2. a pointer to an instance of B handled in other place
- When A is destroyed
-- Case 1. B is destroyed in A destructor with a delete
-- Case 2. B is not destroyed. The owner has to destroy it
The problem of Case 2 it is that it is possible that B owner destroys B before A is destroyed... so if A is used in between, it can cause problems.
What is the proper way to do it?
class A { B b; }
struct Foo : Pte<Foo> {String text;}; CONSOLE_APP_MAIN { Ptr<Foo> ptr; { Foo foo; foo.text = "Text"; ptr = &foo; Cout() << (void*)~ptr << " -> " << ptr->text << "\n"; } Cout() << (void*)~ptr << "\n"; // foo was destroyed but this is totally valid, as ptr == 0 }