0

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?

waas1919
  • 2,365
  • 7
  • 44
  • 76
  • 1
    `std::vector` requires to operate on [copyable types](https://en.cppreference.com/w/cpp/container/vector) which `Poco::NotificationQueue` apparently isn't. – πάντα ῥεῖ Sep 11 '18 at 16:31
  • NotificationQueue has no copy constructor, push_back in your context will create a copy. Create a vector of pointers (smart) to them. – arynaq Sep 11 '18 at 16:31

1 Answers1

2

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;
}
waas1919
  • 2,365
  • 7
  • 44
  • 76