+ 1

How do you make one class inherit from another in c++ using separate files??

how is this implemented using the header file and source file..

21st Feb 2018, 9:09 PM
Otumian Empire
Otumian Empire - avatar
3 Answers
+ 1
For example,there is a class in a.cpp: class a{...}; and you want to inherit it in b.cpp: #include "a.cpp" class b:a{...}; //Can be done directly.
21st Feb 2018, 9:21 PM
langyo
langyo - avatar
+ 1
what about the header files
21st Feb 2018, 10:01 PM
Otumian Empire
Otumian Empire - avatar
+ 1
The child class has to know the parent class. This, an include statement is needed. In file parent.h declare the parent class: class parent {...}; In file child.h declare the child class: #include “parent.h” class child : public parent // in c++ there are 3 different inheritance levels, but ‘public’ is most common {...};
4th Mar 2018, 9:53 PM
K Locher
K Locher - avatar