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

时间:2016-02-24 03:32:25

标签: c++ design-patterns constructor bridge

我正在学习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是我指向实现类的指针:

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

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

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

出了什么问题?

1 个答案:

答案 0 :(得分:3)

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

你可能想要

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