Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail NNTP-Posting-Date: Wed, 01 Feb 2012 01:11:08 -0600 From: Gareth Owen Newsgroups: comp.lang.c++ Subject: Re: why bug in the program References: <3ad325e8-25e0-4f40-a145-d2faa35fe4ed@q8g2000pbb.googlegroups.com> Date: Wed, 01 Feb 2012 07:11:09 +0000 Message-ID: <87wr87do4y.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:u5JInNQWZt5W5l7+jG4JNqH6ico= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Lines: 36 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-A7H/ZiA3lENCBy5cdtATLbCE0/G3zqVWv29yAsL8vFv3dkWYRgqdqYj/ziLRoTGJvE95IuaZf2bnkWB!23ysLNpdMZiUEPnIbO5mUFaSGrpzUsHKPYy3UD5C43oDgJedJUAltPdAulaR66Xy/fU= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2064 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:13684 prava sahoo writes: > class foo > { > static int xxx; > static int zzz; > }; > static int xxx =2; > int foo::xxx = 1; // error here You've already declared foo::xxx to be an int (i.e. specified its type), as part of the definition of class foo. You cannot specify its type again, and need only now set its value. foo::xxx = 1; // the compiler already knows it's an int. > static int zzz =2; This isn't foo::zzz (a variable common to "class foo"), its an unrelated file-local variable that happens to be called zzz. The keyword "static" doesn't quite mean the same thing here as it does in the class definition. A more modern way would be to say: namespace { int zzz = 2; } this will cause the compiler to give it a name like _mxyzptlk::zzz, so we know that it isn't foo::zzz. (There are other technical differences w.r.t. visibility and linkage, but don't worry about those). > (gcc 2.4.5) That's a really, really old compiler...