使用桥接模式 C++ 实现复制构造函数

Implement copy constructor with bridge pattern c++

我正在学习 C++ 并尝试实现桥接模式,发生这种情况时,我有带有构造函数的实现文件:

 SystemImpl::SystemImpl() {
    this->name = "";
    this->value = 0.0;
    this->maxValue = DBL_MAX;
}

SystemImpl::SystemImpl(const SystemImpl& sys) {
    this->name = sys.name;
    this->value = sys.value;
    this->maxValue = sys.maxValue;
}

现在,我正在创建使用此实现的接口,其中 imps 是我指向实现的指针 class:

System::System() {
    imps = new SystemImpl();
}

System::System(const System& sys) {
    imps = new SystemImpl(sys);
}

第一个构造函数工作正常,但第二个是复制构造函数,显示 没有匹配函数来调用‘SystemImpl::SystemImpl(const System&)’

怎么了?

对于imps = new SystemImpl(sys);,编译器抱怨SystemImpl没有一个以System作为参数的构造函数。

你可能想要

System::System(const System& sys) {
    imps = new SystemImpl(*sys.imps);
}