fork download
  1. #include <string>
  2. #include <cstdint>
  3. #include <iostream>
  4.  
  5. class Animal
  6. {
  7. private:
  8. std::uint8_t m_uchLegs;
  9. std::string m_strSpecies;
  10.  
  11. public:
  12. Animal(std::uint8_t uchLegs = 0, const std::string& strSpecies = "")
  13. : m_uchLegs(uchLegs), m_strSpecies(strSpecies) {};
  14.  
  15. std::uint8_t getLegs() const;
  16. std::string getSpecies() const { return m_strSpecies; }
  17. void presentYourself() const;
  18. };
  19.  
  20. class Cat : public Animal
  21. {
  22. public:
  23. Cat() : Animal(4, "Cat") { }
  24. };
  25.  
  26. int main()
  27. {
  28. Cat c;
  29. Animal& a = c;
  30. std::cout << "a's species: " << a.getSpecies() << '\n';
  31. }
  32.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
a's species: Cat