复制构造函数隐式删除,因为默认定义格式不正确

时间:2018-01-04 22:53:00

标签: c++ copy-constructor default-copy-constructor

我正处于用c ++构建伯克利模拟的开始阶段。我一直收到这个错误,但我并不理解它的含义。我在互联网上查了一下,如果我没有默认的构造函数,它会说有问题。但我在所有课程中都有一个。当我在channel中添加TimeSlave变量时会发生此问题。可以请别人帮忙吗?

错误是:

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

并且有一条注释表示复制构造函数被隐式删除,因为默认格式不正确...

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

0 个答案:

没有答案