Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- class Animal {
- public:
- Animal(string name, int age): name(name), age(age) {}
- inline int getAge() const {
- return this->age;
- }
- friend ostream& operator << (ostream &out, const Animal &animal) noexcept ;
- private:
- string name;
- int age;
- };
- ostream& operator << (ostream &out, const Animal &animal) noexcept {
- out << animal.name << ' ' << animal.age;
- return out;
- }
- class Dog : public Animal {
- public:
- Dog(string name, int age): Animal(name, age) {}
- };//*/
- class Cat : public Animal {
- public:
- Cat(string name, int age): Animal(name, age) {}
- };
- int main() {
- vector<Animal> animals = {
- Dog("azor", 11), Cat("thomas", 5), Dog("rex", 12)
- };
- sort(animals.begin(), animals.end(), [](const auto &fi, const auto &se) {
- return fi.getAge() < se.getAge();
- });
- for (const auto &animal : animals) {
- cout << animal << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement