I'm reading C++ Primer Plus by Stephen Frata. I've read up to chapter 6, which means I learned about pointers but not about objects and classes (Although I know about OOP).
I came from a ActionScript (Flash) and Java background, so I never dealt with pointers before, but I understand them. I have a bunch of questions about them though.
As I understood, you need to pair new and delete, i.e. the object/function that creates a pointer is responsible for freeing it. But imagine a simple factory function, like this :
SomeObject * createSomeObject(){
return new SomeObject;
}
That looks pretty problematic. Who is responsible for freeing this pointer now?
What if I create a class that gives public access to a pointer that it created. Following the new/delete rule, this class should be responsible for freeing the pointer in its destructor. But since the pointer might be used by another class, destroying the first class would breaks the second...
Those two interrogations are similar. What can I do to manage a pointer that is known to other entities than the one who created it?
Note : I'm aware that smart pointer could solve this problem, but I'm wondering how people do without them.