How can I make an object know what container it is in?
You should not need to do so ever in a proper class design. There are things like Dependency Injection, but I think that's beyond your actual needs.
Is this a valid implementation?
No
How can I use this if I split the classes into multiple header files, because each class requires the other?
Use forward declarations (have a look here for more details).
Can I use a reference instead of the pointer to Manager in item class (because I don't like pointers)?
No, you cannot.
More in depth beyond your actually asked questions, it seems to be a design issue in the end, and you're asking for XY problems.
That you don't like (raw) pointers is a very good guts feeling, what might be wrong with your actual design. Well, unfortunately you can't manage references using standard containers like std::unordered_set
.
What you can do though, is using smart pointers as provided from the Dynamic memory management facilities.
Primary decision you have to take is, which of the various smart pointers like std::shared_pointer
, std::weak_ptr
or std::unique_ptr
is the right one to manage your necessary ownership requirements semantically correct.
Also Manager
might not be the best naming choice for what you want to do. Lookup the classic Design Patterns please, if there's something fitting better from these.
For example, it sounds you need something like an Observer, that tracks a number of Item
changes/events, and forwards these to other registered Item
instances.
Because Observer
doesn't need to have ownership for any of the registered Item
instances, a std::weak_ptr
seems to be the right choice to reference any of them.