home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1991 / 01 / cppkurs / bug3.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-02  |  1.3 KB  |  58 lines

  1. //----- Anfang BUG3.CPP ------------------------------------
  2. //    (c) 1990 by Thole Groeneveld & toolbox
  3.  
  4. // Compilerfehler unabhängig von class ostream
  5. // Beweis durch Ersatz von ostream durch
  6. // dummy Klasse ausgabe
  7.  
  8. class ausgabe {
  9. public:
  10.     ausgabe& operator << (int); // für x und y der
  11. // Klassen A und B
  12. };
  13.  
  14. ausgabe& ausgabe::operator << (int i) {
  15. i++;    // nur um Warnung auszuschalten
  16. return *this;
  17. }
  18.  
  19. class A {     // entspricht class smanip_int aus iomanip.h
  20. public:
  21. friend ausgabe& operator << (ausgabe&, const A&);
  22. private:
  23. int x;
  24. };
  25.  
  26. // Fehler tritt nur auf bei Keyword inline oder natürlich
  27. // bei Definition von << in der Klassendeklaration
  28. // C++ - Compileroption :
  29. //
  30. // [ ] Out-of-line Inline Function
  31.  
  32. inline ausgabe& operator << (ausgabe& os, const A& a) {
  33. os << a.x;
  34. return os;
  35. }
  36.  
  37. A dummy() {    // entspricht setw(int) aus iomanip.h
  38. A a;
  39. return a;
  40. }
  41.  
  42. class B {    // entspricht class Time aus timeclss.h
  43. public:
  44. friend ausgabe& operator << (ausgabe&, const B&);
  45. private:
  46. int y;
  47. };
  48.  
  49. ausgabe& operator << (ausgabe& os, const B& b) {
  50. os << dummy() << b.y;
  51. // Fehlermeldung :
  52. // B::y is not accessible in function operator << ...
  53. return os;
  54. // Warnung :
  55. // Parameter 'b' is never used in function ...
  56. }
  57. //----- Ende BUG3.CPP --------------------------------------
  58.