home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16540 < prev    next >
Encoding:
Internet Message Format  |  1992-11-18  |  1.1 KB

  1. Path: sparky!uunet!know!cass.ma02.bull.com!mips2!news.bbn.com!usc!zaphod.mps.ohio-state.edu!darwin.sura.net!uvaarpa!murdoch!virginia.edu!gs4t
  2. From: gs4t@virginia.edu (Gnanasekaran Swaminathan)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re:  sizeof( data member )
  5. Message-ID: <1992Nov19.002201.14321@murdoch.acc.Virginia.EDU>
  6. Date: 19 Nov 92 00:22:01 GMT
  7. References: <1992Nov18.171207.16636@bnrmtl.bnr.ca>
  8. Sender: usenet@murdoch.acc.Virginia.EDU
  9. Organization: University of Virginia
  10. Lines: 24
  11.  
  12. john@bnrmtl.bnr.ca (John Hickin) writes:
  13. :     class Foo
  14. :     {
  15. :             char Data[ 200 ];
  16. :     public:
  17. :         static void foo( int );
  18. :         ...etc.
  19. :     };
  20. :     void Foo :: foo( int needed )
  21. :     {
  22. :         if ( !(needed <= sizeof(Foo::Data)) ) complain();
  23. :     }
  24. : Of course I can use the enum { Size = 200 } to work around the problem.
  25. : The question is, should the langauge allow you to take the size of a
  26. : data member without having an object in hand?
  27.  
  28. You can do
  29.     sizeof(Foo().Data)
  30. to find out the size of member Data. It works in gcc 2.2.2
  31. after you provide a default constructor to class Foo.
  32.  
  33. -Sekar
  34.