#include <iostream>
class human {
public:
int height;
int weight;
public:
human(int h, int w) {
height = h;
weight = w;
}
int get_height() const {
return height;
}
int get_weight() const {
return weight;
}
virtual void print_all() = 0; // ()=0 creates a _pure_ virtual function that must be overridden.
//Alternatively you can just write a default function as a virtual function with no requirement to be overwritten.
};
class adult : public human { // inherit from human class
public:
std::string occupation;
public:
adult(int h, int w) : human(h, w) {
occupation = "doctor";
} // call the base class constructor from this constructor
std::string get_occupation() const {
return occupation;
}
void print_all() { // virtual function overridden in derived class
std::cout << height << std::endl;
std::cout << weight << std::endl;
std::cout << occupation << std::endl;
}
};
int main() {
adult obj(180, 220); // object of derived class
std::cout << obj.get_occupation() << std::endl;
obj.occupation = "lawyer";
obj.print_all();
return 0;
}