std::shared_ptrと を使用してオブジェクトをジャグリングしようとしていますstd::weak_ptr。シナリオは次のようなものです。
channel抽象クラスから派生したクラスのオブジェクトがありますabstract::channel(純粋仮想関数を使用)。オブジェクトへの共有ポインタ ( ) を含むコンテナchannelContainer( ) があります。std::vectorstd::shared_ptrchannel
これで、内の各オブジェクトへのdeque (std::deque)ウィーク ポインターを含むができました。この両端キューに名前を付けましょう。(std::weak_ptr)channelContainerfreeChannelQueue
だから言いましょう:
std::vector<std::shared_ptr<abstract::channel> > channelContainer;
std::deque<std::weak_ptr<abstract::channel > > freeChannelQueue;
//Assuming that both the containers are filled appropriately How do I go about implementeing the below functions?
abstract::channel& get_free_channel() {
//This should return a free channel object from 'freeChannelQueue' and pop the queue.
}
bool release_channel(abstract::channel& ch) {
//This should convert 'ch' to a std::weak_ptr (or std::shared_ptr) and push it to 'freeChannelQueue'
}
「オブジェクトへの参照を弱いポインタに変換する方法は?」に特に興味があります。