I am trying to juggle objects using std::shared_ptr
and std::weak_ptr
. The scenario is something like this:
I have objects of class chann
You cannot
convert a reference to an object to a weak pointer
You can make a weak pointer from a shared pointer, just using assignment =
e.g.
std::shared_ptr get_free_channel();
then
bool release_channel(std::shared_ptr ch)
{
std::weak_ptr weak_ch = ch;
//...
}
Watch out for lifetimes - will the shared_ptr go before the weak pointers that point to them?