mardi 30 novembre 2021

Compilation Error - Binding reference discards qualifiers

I am getting this compilation error when trying to compile inher2.cpp How do I correctly assign eventQueue to m_eventQueue ? I made this MSVP to see if I could proceed further but haven't been successful.

inher2.cpp:7:26: error: binding reference of type ‘std::shared_ptr<EventQueue>&&’ to ‘std::remove_reference<const std::shared_ptr<EventQueue>&>::type {aka const std::shared_ptr<EventQueue>}’ discards qualifiers
  m_eventQueue = std::move(eventQueue);
                 ~~~~~~~~~^~~~~~~~~~~~

inher2.cpp

#include<iostream>
#include"inher2.hpp"

RecordingConfigJobStateSignal::RecordingConfigJobStateSignal( const EventQueuePtr& eventQueue )
{
        /* m_eventQueue is actually from class commonQueue */
        m_eventQueue = std::move(eventQueue);
}

int main()
{
        return 0;
}

inher2.hpp

#include<iostream>
#include<memory>
#include<queue>
using namespace std;
class EventBase
{
public:

private:
        int a;
};
using EventBasePtr = std::shared_ptr<EventBase>;

class SubscriptionManager
{

        public:
                int x;
};

class EventQueue
{
public:
    explicit EventQueue( SubscriptionManager& );
    ~EventQueue();
    EventQueue& operator = (const EventQueue &)
    {
        return *this;
    }
private:
    std::queue< EventBasePtr >          m_queue;
};
using EventQueuePtr = std::shared_ptr<EventQueue>;


class commonQueue
{
        public:
                int *a;
                static std::queue< EventBasePtr >       m_queue;
                const EventQueuePtr m_eventQueue;
};

class RecordingConfigJobStateSignal: public commonQueue
{
        public:
                int c;
                RecordingConfigJobStateSignal( const EventQueuePtr &);
        private:
                int b;

};

I fixed one error prior to this by using std::move but stuck at the error discussed above.

inher2.cpp:7:17: error: cannot bind rvalue reference of type ‘std::shared_ptr<EventQueue>&&’ to lvalue of type ‘const EventQueuePtr {aka const std::shared_ptr<EventQueue>}’
  m_eventQueue = eventQueue;
                 ^~~~~~~~~~

Aucun commentaire:

Enregistrer un commentaire