C++ Poco - 如何创建通知队列的向量?

C++ Poco - How to create a vector of NotificationQueue's?

本文关键字:通知 队列 向量 创建 Poco 何创建 C++      更新时间:2023-10-16

我想创建一个通知中心,在那里我处理所有notificationsthreads

我无法在软件启动时知道我需要多少notification队列。在run-time期间可能会有所不同。

所以我创建了这个(代码简化(:

#include <vector>
#include "Poco/Notification.h"
#include "Poco/NotificationQueue.h"
using Poco::Notification;
using Poco::NotificationQueue;
int main()
{
std::vector<NotificationQueue> notificationCenter;
NotificationQueue q1;
NotificationQueue q2;
notificationCenter.push_back(q1); //ERROR: error: use of deleted function ‘Poco::NotificationQueue::NotificationQueue(const Poco::NotificationQueue&)’
notificationCenter.push_back(q2);
return 0;
}

我得到了error: use of deleted function ‘Poco::NotificationQueue::NotificationQueue(const Poco::NotificationQueue&)’

我明白。我无法复制或分配NotificationQueue.

问题:

有什么方法可以在不静态创建NotificationQueue向量的情况下处理它们?

@arynaq评论中,指针向量将使工作:

#include <memory>
#include <vector>
#include "Poco/Notification.h"
#include "Poco/NotificationQueue.h"
using Poco::Notification;
using Poco::NotificationQueue;
int main()
{
std::vector<std::shared_ptr<NotificationQueue>> notificationCenter;
std::shared_ptr<NotificationQueue> q1 = std::make_shared<NotificationQueue>();
std::shared_ptr<NotificationQueue> q2 = std::make_shared<NotificationQueue>();
notificationCenter.push_back(q1);
notificationCenter.push_back(q2);
return 0;
}