+ 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..
4 Antworten
+ 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.
+ 1
what about the header files
+ 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
{...};