home *** CD-ROM | disk | FTP | other *** search
- 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
- From: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Newsgroups: comp.lang.c++
- Subject: Re: sizeof( data member )
- Message-ID: <1992Nov19.002201.14321@murdoch.acc.Virginia.EDU>
- Date: 19 Nov 92 00:22:01 GMT
- References: <1992Nov18.171207.16636@bnrmtl.bnr.ca>
- Sender: usenet@murdoch.acc.Virginia.EDU
- Organization: University of Virginia
- Lines: 24
-
- john@bnrmtl.bnr.ca (John Hickin) writes:
- : class Foo
- : {
- : char Data[ 200 ];
- : public:
- : static void foo( int );
- : ...etc.
- : };
- :
- : void Foo :: foo( int needed )
- : {
- : if ( !(needed <= sizeof(Foo::Data)) ) complain();
- : }
- :
- : Of course I can use the enum { Size = 200 } to work around the problem.
- : The question is, should the langauge allow you to take the size of a
- : data member without having an object in hand?
-
- You can do
- sizeof(Foo().Data)
- to find out the size of member Data. It works in gcc 2.2.2
- after you provide a default constructor to class Foo.
-
- -Sekar
-