Is this the proper (best) way to initialize both the constructor of the parent class (in this case an interface) and the constructor of the child class?
class Parent {
protected:
int x, y;
private:
int pvt = 2;
public:
int pub = 3;
Parent(int n1, int n2)
: x(n1), y(n2) {}
virtual void merge_parent() {
std::cout << "[parent]: " << x << y << pvt << pub << std::endl;
}
virtual void merge() = 0;
};
class Child : public Parent {
private:
int c;
public:
Child(int n1, int n2, int n3): Parent(n1, n2), c(n3) {}
void merge() override {
std::cout << "[child]: " << x << y << c << pub << std::endl;
}
};
int main() {
Child* p = new Child(1, 2, 3);
p->merge_parent();
p->merge();
}
Parent* p = new Child(1,2,3); delete p;wont workParentChildsays nothing about class responsibility (it describe relations, which is not helpful), also when I seemergeI expect argument what should be merged.