home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13173 < prev    next >
Encoding:
Text File  |  1992-09-01  |  1.3 KB  |  56 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!world!rr
  3. From: rr@world.std.com (Robert I Ransbottom)
  4. Subject: Initialization of external vars
  5. Message-ID: <BtxJrw.CB5@world.std.com>
  6. Followup-To: comp.lang.c++
  7. Summary: ???
  8. Sender: rr@world.std.com
  9. Organization: The World Public Access UNIX, Brookline, MA
  10. Distribution: usa
  11. Date: Wed, 2 Sep 1992 02:47:54 GMT
  12. Lines: 42
  13.  
  14. // Seems that this should run true. [ C++3.0 ref man 3.4, 3.5, 6.7]
  15. // What am I missing?
  16. //
  17. // code & sample run follows,
  18. // rr@world.std.com
  19.  
  20. #include <stream.h>
  21.  
  22. class boolean {
  23.  public:
  24.         int boo;
  25.  public:
  26.   boolean(int a):
  27.          boo((cerr << "initializing boo: " << boo << "\n", !!a)) {
  28.                 cerr << "assigning boo: " << boo << "\n";
  29.                 boo = !!a;
  30.         }
  31.         operator int () const {
  32.                 cerr << "convert boolean to int\n";
  33.                 return boo;
  34.         }
  35. };
  36.  
  37. boolean TRUE = 1;
  38. main()
  39. {
  40.         if (TRUE) {
  41.                 cout << "boolean TRUE -- True.\n";
  42.         } else {
  43.                 cout << "boolean TRUE -- False.\n";
  44.         }
  45.         if (TRUE.boo) {
  46.                 cout << "boolean TRUE.boo-- True.\n";
  47.         } else {
  48.                 cout << "boolean TRUE.boo-- False.\n";
  49.         }
  50. }
  51. // $ boolean
  52. // convers. boolean to int
  53. // boolean TRUE -- False.
  54. // boolean TRUE.boo-- False.
  55.  
  56.