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

  1. Xref: sparky comp.lang.c++:13213 comp.os.ms-windows.programmer.misc:1648 comp.os.ms-windows.programmer.tools:840
  2. Newsgroups: comp.lang.c++,comp.os.ms-windows.programmer.misc,comp.os.ms-windows.programmer.tools,comp.windows.ms.programmer
  3. Path: sparky!uunet!taumet!steve
  4. From: steve@taumet.com (Steve Clamage)
  5. Subject: Re: I Borland C++/Win 3.1 Broken??? Help!
  6. Message-ID: <1992Sep2.164949.11421@taumet.com>
  7. Organization: TauMetric Corporation
  8. References: <1992Sep1.213224.7550@actrix.gen.nz>
  9. Date: Wed, 2 Sep 1992 16:49:49 GMT
  10. Lines: 34
  11.  
  12. David.Haigh@bbs.actrix.gen.nz writes:
  13.  
  14. >The following member function compiles without error, using Turbo C++
  15. >for Windows 3.0.
  16.  
  17. >virtual int yield( volatile BOOL & continueYield = TRUE);
  18.  
  19. >BOOL : typedef for int
  20. >TRUE : #define 1
  21.  
  22. >However, using Borland C++ for Windows 3.1, the following errors are generated:
  23.  
  24. >* Reference initialised with 'int', needs lvalue of type int.
  25. >* Type mismatch in default value for parameter 'continueYield'.
  26.  
  27. It looks like Borland fixed a compiler bug in the later release.
  28.  
  29. You cannot initialize a non-const referernce with a constant.
  30. TRUE is a literal (constant) integer, and may be passed only to a
  31. a const reference.  If a function has a non-const reference parameter,
  32. it is allowed to change the passed-in value.  You can't change a
  33. literal constant, which is why it is illegal.
  34.  
  35. Either pass in a variable initialized to TRUE, or declare the function
  36. parameter to be a const reference.  If it does not change the value of
  37. its actual argument, it should be declared const anyway.  If it does
  38. change its actual argument, you can't pass it a literal.
  39.  
  40. This is legal, assuming you really want 'volatile' as well:
  41.     virtual int yield( const volatile BOOL & continueYield = TRUE);
  42. -- 
  43.  
  44. Steve Clamage, TauMetric Corp, steve@taumet.com
  45. Vice Chair, ANSI C++ Committee, X3J16
  46.