fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Animal {
  5. public:
  6. Animal() {}
  7. };
  8.  
  9. class Cat: public Animal {
  10. public:
  11. int someThing;
  12.  
  13. Cat(): Animal() {
  14. this->someThing = 42;
  15. }
  16. };
  17.  
  18. int main() {
  19. // Cat* a = new Cat(); // Works
  20. Animal* a = new Cat(); // Does not work
  21. cout << a->someThing << endl;
  22.  
  23. return 0;
  24. }
Compilation error #stdin compilation error #stdout 0s 16064KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:21:14: error: ‘class Animal’ has no member named ‘someThing’
   cout << a->someThing << endl;
              ^~~~~~~~~
stdout
Standard output is empty