I have problem in my project. I believe shared/weak pointers from new c++ stabdards can solve it but its unclear to me how. In book i read about standard library there is no comment on my idea how to use these pointers.
In my application i have Library
class. This class has internal vector
of Book
objects. These objects usually created inside Library
class, though external code queries Books
objects from it using functions and uses them later. Each Book
instance has a public pointer to 'host' Library
instance.
Sometimes external code deletes Library
and creates new, but it may still use previously queried Book
objects from old library. My problem is that Book
class should drop pointer that no longer valid, so book will not contain invalid pointer to deleted library instance.
It is unclear for me how to implement weak pointers to book class to achieve such behavior.