【发布时间】:2021-03-17 09:15:41
【问题描述】:
我正在寻找一种在子类中完成一些更改后启动父类的方法。
例如:
class Parent {
public:
Parent(stream f) {
//some code
}
};
class Child : public Parent {
public:
Child(string fileName) : Parent(???) { // Line 10
//some code
}
};
在第 10 行,我应该给出使用“fileName”创建的 fstream。 我在哪里可以创建这个流变量?
【问题讨论】:
-
您可以在
???所在的位置创建它。Parent(std::fstream(filename)) -
Where can I create this stream variable?在???创建它有什么问题? -
但是当涉及到更复杂的工作时,我不能只用一个函数/行来做到这一点。
-
But when it comes to more complicated work, I couldn't do this in just one function/line.为什么你认为会这样?您需要展示一个示例,说明您认为在哪种情况下它不起作用。 -
或者直接调用lambda。
标签: c++ oop inheritance