fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. //class Engine
  5.  
  6. class Car;
  7. class Engine
  8. {
  9. private:
  10. int CC_;
  11. string type_;
  12. int weight_;
  13. friend void check_engine(Car&);
  14. friend class Car;
  15. friend void check_my_engine(void);
  16.  
  17. public:
  18. //Engine constructor
  19. Engine(int c, string t, int w)
  20. : CC_(c)
  21. , type_(t)
  22. , weight_(w)
  23. {
  24. cout << "Engine!" << '\t'
  25. << "CC: " << c << '\t'
  26. << "Type: " << t << '\t'
  27. << "Weight: " << w << '\n';
  28. }
  29.  
  30. //Engine destructor
  31. ~Engine()
  32. {
  33. cout << "Engine destructor!" << endl;
  34. }
  35. };
  36.  
  37. //class Car - Inheritance class Engine
  38. class Car
  39. {
  40. private:
  41. Engine my_engine;
  42. friend void check_engine(Car&);
  43.  
  44. public:
  45. //Car constructor
  46. Car(int c, string t, int w)
  47. : my_engine(c, t, w)
  48. {
  49. cout << "Car!" << '\t'
  50. << "CC: " << c << '\t'
  51. << "Type: " << t << '\t'
  52. << "Weight: " << w << endl;
  53. }
  54.  
  55. //function-check_my_engine
  56. void check_my_engine(void)
  57. {
  58. cout << "Check my engine!" << '\t';
  59. cout << "CC: " << my_engine.CC_ << '\t'
  60. << "Type: " << my_engine.type_ << '\t'
  61. << "Weight: " << my_engine.weight_ << endl;
  62. }
  63. //Car destructor
  64. ~Car()
  65. {
  66. cout << "Car destructor!" << endl;
  67. }
  68. };
  69.  
  70. //function-check_engine
  71. void check_engine(Car& bu)
  72. {
  73. cout << "Check engine!" << '\t';
  74. cout << "CC: " << bu.my_engine.CC_ << '\t'
  75. << "Type: " << bu.my_engine.type_ << '\t'
  76. << "Weight: " << bu.my_engine.weight_ << endl;
  77. }
  78.  
  79. int main()
  80. {
  81. Car car(99, "wow", 99);
  82.  
  83. check_engine(car);
  84.  
  85. check_my_engine(void);
  86.  
  87. return 0;
  88. }
  89.  
  90.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:85:21: error: expected primary-expression before 'void'
     check_my_engine(void);  
                     ^
prog.cpp:85:25: error: 'check_my_engine' was not declared in this scope
     check_my_engine(void);  
                         ^
stdout
Standard output is empty