home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11405 < prev    next >
Encoding:
Text File  |  1992-07-23  |  1.9 KB  |  63 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!haven.umd.edu!wam.umd.edu!krc
  3. From: krc@wam.umd.edu (Kevin R. Coombes)
  4. Subject: Re: boolean (was: Re: typedef vs enum)
  5. Message-ID: <1992Jul23.125431.19324@wam.umd.edu>
  6. Sender: usenet@wam.umd.edu (USENET News system)
  7. Nntp-Posting-Host: wam.umd.edu
  8. Organization: University of Maryland, College Park
  9. References: <DOUGM.92Jul19222728@titan.cs.rice.edu> <DAVEG.92Jul20220553@synaptx.synaptics.com> <1992Jul21.170922.26941@ucc.su.OZ.AU>
  10. Date: Thu, 23 Jul 1992 12:54:31 GMT
  11. Lines: 50
  12.  
  13. In article <1992Jul21.170922.26941@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  14. >    While we're talking of a boolean type (which has two
  15. >values equivalent to 0 and 1), how about a ZERO type?
  16. >
  17. >    Type ZERO only has ONE value---0 of course.
  18. >
  19. >    What use is it, you ask?
  20. >
  21. >    Plenty. 0 is very important.
  22. >
  23. >    How often have you wanted to allow assignment
  24. >or initialisation of a class to 0 (but not any other value?)
  25. >
  26. >    For example, if p is a pointer, you can write
  27. >
  28. >    p=0; // null pointer
  29. >
  30. >But if it is a *smart* pointer, you would have to declare
  31. >assignment of say int->smart, and give a run-time error
  32. >if the int was non-zero.
  33. >
  34. >[There are NO variables of type zero, the type name is, of course 0]
  35. >
  36. >    class smart {
  37. >        operator=(0) { // set pointer to null state }
  38. >    };
  39. >
  40. >Anyone?
  41. >    
  42. >
  43. >-- 
  44. >;----------------------------------------------------------------------
  45. >        JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  46. >    Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  47. >;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  48.  
  49. I liike this idea (but don't expect it to go anywhere). After all,
  50. 0 is a type different from any other integer. If, for example, you have
  51. an overloaded function
  52.  
  53. void f(long);
  54. void f(void *);
  55.  
  56. the call f(0) is an error, because it is ambiguous. No other integer
  57. has that property.
  58.  
  59. But shouldn't the type be called NULL? :-)
  60.  
  61. Kevin Coombes <krc@math.umd.edu>
  62.  
  63.