0

我正在开始用 C++ 构建一个伯克利模拟。我不断收到此错误,但我不明白它的含义。我在互联网上查了一下,它说如果我没有默认构造函数就会出现问题。但我在所有课程中都有一个。当我将channel变量添加到TimeSlave. 可以请人帮忙吗?

错误是:

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

并且有一条注释说复制构造函数被隐式删除,因为默认值格式错误...

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{
    Pipe<long> pipe1;
    Pipe<long> pipe2;

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

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

类管道:

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

0 回答 0