error: invalid new-expression of abstract class type Tins::PDU

  c++

I’m using libtins to capture packets and moodycamel Concurrent Queue to queue captured packets.

This std::make_unique<Tins::PDU>(pdu.clone()) fails to compile,

error: invalid new-expression of abstract class type Tins::PDU { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }

I was using the answer given by the user of my co-related question.

The PDU type is an abstract class. How to fix this as It seems make_unique need to know the sub class type?

Like, std::unique_ptr<A> bse = std::make_unique<B>(bObject); but I can’t know the B aka sub class type in advance.

moodycamel::ConcurrentQueue<std::unique_ptr<Tins::PDU>> packetQueue;

void worker()
{
    while(true) {
        std::unique_ptr<Tins::PDU> pdu;

        if(packetQueue.try_dequeue(pdu) == false) {
            continue;
        }

        // Do Work on *pdu
    }
}

bool callback(PDU &pdu)
{
  packetQueue.enqueue(std::make_unique<Tins::PDU>(pdu.clone()));

  return true;
}

Source: Windows Questions C++

LEAVE A COMMENT