使用桥接模式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是指向实现类的指针:使用桥接模式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; },c++,design-patterns,constructor,bridge,C++,Design Patterns,Constructor,Bridge,现在,我正在创建使用此实现的接口,其中imps是指向实现类的指针: System::System() { imps = new SystemImpl(); } System::System(const System& sys) { imps = new SystemImpl(sys); } 第一个构造函数工作正常,但第二个是复制构造函数,显示 调用'SystemImpl::SystemImpl(const System&')时没有匹配的函数。 怎么了?对于imps=n
System::System() {
imps = new SystemImpl();
}
System::System(const System& sys) {
imps = new SystemImpl(sys);
}
第一个构造函数工作正常,但第二个是复制构造函数,显示
调用'SystemImpl::SystemImpl(const System&')时没有匹配的函数。
怎么了?对于
imps=newsystemimpl(sys)代码>,编译器抱怨SystemImpl
没有将System
作为其参数的构造函数
你可能想要
System::System(const System& sys) {
imps = new SystemImpl(*sys.imps);
}
SystemImpl是系统的实现,我使用接口中的实现,而不是相反,我猜这似乎是“只是读取错误消息”的情况。。。