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

  1. //----- Anfang BUG2.CPP ------------------------------------
  2. //    (c) 1990 by Thole Groeneveld & toolbox
  3. //
  4.  
  5. #include <iostream.h>
  6.  
  7. class A { // entspricht class smanip_int aus iomanip.h
  8. public:
  9. friend ostream& operator << (ostream&, const A&);
  10. private:
  11. int x;
  12. };
  13.  
  14. // Fehler tritt nur auf bei Keyword inline oder natürlich
  15. // bei Definition von << in der Klassendeklaration
  16. // C++ - Compileroption :
  17. //
  18. // [ ] Out-of-line Inline Function
  19.  
  20. inline ostream& operator << (ostream& os, const A& a) {
  21. os << a;
  22. return os;
  23. }
  24.  
  25. A dummy() {// entspricht setw(int) aus iomanip.h
  26. A a;
  27. return a;
  28. }
  29.  
  30. class B {    // entspricht class Time aus timeclss.h
  31. public:
  32.     friend ostream& operator << (ostream&, const B&);
  33. private:
  34.     int y;
  35. };
  36.  
  37. ostream& operator << (ostream& os, const B& b) {
  38.     os << dummy() << b.y;
  39.     // Fehlermeldung :
  40.     // B::y is not accessible in function operator << ...
  41.     return os;
  42.     // Warnung :
  43.     // Parameter 'b' is never used in function ...
  44. }
  45. //----- Ende BUG2.CPP --------------------------------------
  46.