Classes in c++ can be extended, creating new classes which retain characteristics of the base class. This means we can create something like this :
struct Person
{
struct Person** children;
char[20] name;
int age;
};
struct Teacher : public Person
{
char[20] subject;
int salary;
};
Does using this alternative make the code run slower than the inheritance version? :
struct Teacher
{
struct Person personal_info;
char[20] subject;
int salary;
};
I personally prefer the second option, because I can clearly see which members come from struct Person
when making variables from type struct Teacher
and accessing those members. If struct Person
has a field of another struct type, I can just typedef
the access to that struct's fields and still see clearly what is going on. Does anything change performance wise? Do I have a good reason to use the first option over the second one?