Copy-constructor deleted implicitly because default definition ill formatted

775 Views Asked by At

I am at the start of building a berkeley simulation in c++. I keep getting this error and I don't understand it's meaning. I looked it up on the internet and it says there are problems if I got no default constructor. But I have one in all classes. This problem occurs when I add the channel variable in TimeSlave. Can please someone help?

The error is:

error: use of deleted function ‘TimeSlave::TimeSlave(TimeSlave&&)’
  : _M_head_impl(std::forward<_UHead>(__h)) { }

And there is a note which says that the copy-constructor is deleted implicitly because the default would be ill formatted...

Class TimeSlave:

class TimeSlave{
    Clock clock;
    Channel channel;
public:
    TimeSlave(string name, int hours, int minutes, int seconds) : clock{name, hours, minutes, seconds} {}
    void operator()(){
        clock();
    }
    Channel* get_channel(){
        return &channel;
    }
};

Class Channel:

class Channel{
    Pipe<long> pipe1;
    Pipe<long> pipe2;

public:
    Channel(){}
    Pipe<long>& get_pipe1(){
        return pipe1;
    }

    Pipe<long>& get_pipe2(){
        return pipe2;
    }
};

Class Pipe:

template <typename T>
class Pipe {
    std::queue<T> backend;
    std::mutex mtx;
    std::condition_variable not_empty;
    bool closed{false};
  public:
    Pipe<T>(){}
    Pipe& operator<<(T value) {
        if(closed) return *this;
        lock_guard<mutex> lg{mtx};
        backend.push(value);
        not_empty.notify_one();
        return *this;
    }

    Pipe& operator>>(T& value) {
        if(closed) return *this;
        unique_lock<mutex> ulck{mtx};
        not_empty.wait(ulck, [this](){ return backend.get_size() == 0; });
        return *this;
    }

    void close() {
        closed = true;
    }

    explicit operator bool() {
        return !closed;
    }
};
0

There are 0 best solutions below