Describe how to construct the header file of a derived class.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Describe how to construct the header file of a derived class.
Let’s assume class “one” is the base class and class “two” is the derived class. To avoid multiple inclusions of these classes, use the following preprocessor commands:
#ifndef one_H
It means that the class “one” is not defined and cannot access the identifiers from the class “one”.
#define one_H
After executing the above statement, the compiler notices that there is no such existing file, hence defines “one_H”
#endif
This command is the end of the “ifndef” command.
Consider an example:
Using preprocessor commands, define “one.h”
//Header files
#ifndef one_H
//define a macro for class “one”
#define one_H
//define a class one
class one {
public:
//declare member functions
int sumDigits();
one():
private:
//declare member variables
int b;
int a:
};
//end the definition of macro of class
#endif
Using preprocessor commands define “two.h” which is derived from class “one”
//Include header files
#ifndef two_H
//define a macro for class two
#define two_H
#include "one.h"
//define a class two from “one” class
class two: public one {
Place the definitions of the class two here
};
//end the definition of macro of class
#endif
Step by step
Solved in 2 steps