Search code examples
c++vectornotificationspoco-librariesdeleted-functions

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


I want to create a Notification Center, where I handle all the notifications to threads.

I can't tell on the software boot how many notification queues I would need. It may vary during run-time.

So I've created this (code simplified):

#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;
}

I'm getting the error: use of deleted function ‘Poco::NotificationQueue::NotificationQueue(const Poco::NotificationQueue&)’

Which I understand. I cannot copy or assign a NotificationQueue.

Question:

Is there any way I can handle a vector of NotificationQueue's without creating them statically?


Solution

  • Taking @arynaq comment, a vector of pointers will make the job:

    #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;
    }