I was wondering why to use inheritence, when you can easily come up with an alternative, which for me is more evident to use:
Let's say we have classes Parent, Child_1, and Child_2:
class Parent {
public:
int x;
}
class Child_1 {
public:
Parent p;
string s;
}
class Child_2 {
public:
Parent p;
char c;
}
How is this different, than:
class Parent {
public:
int x;
}
class Child_1 : public Parent {
public:
string s;
}
class Child_2 : public Parent {
public:
char c;
}
I understand that using inheritance allows us to use private, protected and public fields separately, but for me it complicates things more than being useful. To be honest, when I used private, it was more of a drawback, that I had to write getter and setter functions for private fields. Now I usually just put everything to public, for the sake of simplicity. Opinions?