给出以下类ConcreteBar实现BarIfc:
class Base {
public:
Base(BarIfc& bar) : _bar(bar) { }
void foo() {
_bar.bar();
}
private:
Base(const Base& other);
Base& operator=(const Base& other);
BarIfc& _bar; // Pure virtual interface
};
class Child : public Base {
public:
// bar is passed to base class before initialization
Child(int i) : Base(_bar), _bar(i) {
}
private:
Child(const Child& other);
Child& operator=(const Child& other);
ConcreteBar _bar;
};
Run Code Online (Sandbox Code Playgroud)
我是否正确地假设这一点
Child(int i) : Base(_bar), _bar(i) {}
Run Code Online (Sandbox Code Playgroud)
只要我不在_bar基类的初始化列表中使用(例如调用方法)引用,它就是"有效"的C++ ?
c++ ×1