fork(187) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. /// implement your class here
  5. class Printer;
  6. ///
  7.  
  8.  
  9. int main() {
  10. Printer printer;
  11.  
  12. printer = 42;
  13. printer.print(); //should print "42" to standard output
  14.  
  15. int* value = new int(10);
  16. printer = value;
  17. printer.print(); // should print "[10]"
  18.  
  19. *value = 20; // the value pointer did not change, changed a value by it
  20. printer.print(); // should print "[20]"
  21.  
  22. float* fvalue = new float(9.81);
  23. printer = fvalue;
  24. printer.print(); // should print "[9.81]"
  25.  
  26. *fvalue = 0.2+0.3;
  27. printer.print(); // should print "[0.5]"
  28.  
  29. printer = std::string("Hello world");
  30. printer.print();
  31. //should print "Hello world"
  32.  
  33. printer = 2.718281;
  34. printer.print();
  35. //should print "2.718281"
  36.  
  37. delete fvalue;
  38. delete value;
  39. return 0;
  40. }
  41.  
  42.  
  43. // the standard output should be:
  44. 42
  45. [10]
  46. [20]
  47. [9.81]
  48. [0.5]
  49. Hello world
  50. 2.71828
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:10:10: error: aggregate ‘Printer printer’ has incomplete type and cannot be defined
  Printer printer;
          ^~~~~~~
prog.cpp: At global scope:
prog.cpp:44:1: error: expected unqualified-id before numeric constant
 42
 ^~
stdout
Standard output is empty