Inheritance in C++
Inheritance is a feature of Object Oriented Programming that allows programmers to create classes based on other classes. A class that inherits from another class will have the same behavior as the parent class unless it is overwritten.
Let’s say we have a class:
1
2
3
4
5
6
7
8
9
class Greeter {
public:
void talk() {
std::cout << greeting_ << std::endl;
}
protected:
std::string greeting_ = "hello";
};