fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. class person {
  7. string name;
  8. public:
  9.  
  10. person(const string &n){
  11. name=n;
  12. }
  13. virtual person& print(const person&){}
  14. };
  15.  
  16. class worker:public person {
  17. int number;
  18. public:
  19. worker(const string &n , int num ):person(n){
  20. number=num;
  21. }
  22.  
  23. virtual worker& print(const worker& x){
  24. cout << number << x.number<< endl;
  25. return number+=number;
  26. }
  27. };
  28.  
  29. int main(int argc, char** argv) {
  30.  
  31. person *p = new worker("john",1);
  32. person *g = new worker("jack",2);
  33. worker c = p->print(*g);
  34.  
  35. return 0;
  36. }
Compilation error #stdin compilation error #stdout 0s 3472KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘virtual person& person::print(const person&)’:
prog.cpp:13:42: warning: no return statement in function returning non-void [-Wreturn-type]
     virtual person& print(const person&){}   
                                          ^
prog.cpp: In member function ‘virtual worker& worker::print(const worker&)’:
prog.cpp:25:24: error: invalid initialization of reference of type ‘worker&’ from expression of type ‘int’
         return number+=number;
                        ^
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:33:27: error: conversion from ‘person’ to non-scalar type ‘worker’ requested
     worker c = p->print(*g);
                           ^
prog.cpp: In member function ‘virtual worker& worker::print(const worker&)’:
prog.cpp:26:5: warning: control reaches end of non-void function [-Wreturn-type]
     }
     ^
stdout
Standard output is empty