我正在学习 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;
}
现在,我正在创建使用此实现的接口(interface),其中 imps 是我指向实现类的指针:
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);
}
关于c++ - 使用桥接模式 C++ 实现复制构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35592725/