我正在尝试使用std::shared_ptr和处理对象std::weak_ptr.场景是这样的:
我有一个类的对象,channel它派生自一个抽象类abstract::channel(使用纯虚函数).我有一个容器channelContainer(std::vector)包含对象的共享指针(std::shared_ptr)channel.
现在,我有一个deque (std::deque)包含弱指针(std::weak_ptr)的每个对象channelContainer.让我们说出这个双端队列freeChannelQueue.
所以我们说:
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 …Run Code Online (Sandbox Code Playgroud)