3 ms·
It's simple. The key is that something has to have _ownership_ of the products. [1] User decides to view a couple of orders. Orders reference products. Those p
by letzjuc 13y ago
It's simple. The key is that something has to have _ownership_ of the products. [1]
User decides to view a couple of orders. Orders reference products. Those products are managed by something (e.g. an unordered_map of shared_ptr). The order can check, is my product there? If so, i'll copy the shared_ptr to it. Otherwise, I create a shared_ptr for a product and store a copy in the manager. When the order's destructor is triggered, you check the count of the shared_ptr. If it is 2 (i.e. the order and the manager), the order removes the shared_ptr.
[1] Single ownership is the key concept, not reference counting which is just an implementation detail.
- danbruc 13y agohttps://news.ycombinator.com/item?id=7315392 https://news.ycombinator.com/item?id=7315392 https://news.ycombinator.com/item?id=7315575 https://news.ycombinator.com/item?id=7315575 (Don't want to duplicate the comment once again.)