Well, in C++, inheritance is a fundamental concept in OOP (object-oriented programming) that allows you to create new classes such as derived or child classes.
Here is the simple example of inheritance in C++.
#include <iostream>
class Base {
public:
void sayHello() {
std::cout << "Hello from Base" << std::endl;
}
};
class Derived : public Base {
public:
void sayHi() {
std::cout << "Hi from Derived" << std::endl;
}
};
int main() {
Derived derivedObj;
derivedObj.sayHello(); // Inherited from Base
derivedObj.sayHi(); // Specific to Derived
return 0;
}
There are many kind of inhertance, if you are looking to know about it in detail then you can read about it from here in detail.
Thanks