🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #814

Re: Init of static members inside class def

#814
From: Mike Stump
Date: Sat, 29 Aug 1992 13:24
44 lines
1478 bytes
g++ -ansi -pedantic will reject this construct with the error message:

t3.cc:2: fields cannot have initializers

This is proper behavior.

The other bevahior that you are seeing is an extension.

> Message-Id: <199208201131.AA19238@inpbox.inp.nsk.su>
> Date: 20 Aug 92 19:23:00 +0007 (GMT+7:00)
> From: "LOPATIN" <lopatin@inp.nsk.su>
> To: "bug-gcc" <bug-gcc@prep.ai.mit.edu>

> 	I admire how your gcc 2.1 works on my DECstation 5000/200
> (Ultrix 4.2), but it seems to be erroneous not to reject
> initialization of the static member inside class definition. Let me
> illustrate it by example:

> [ 191 > cat one.C
> #include <iostream.h>

> struct item {
>     static int y = 1;
> };

> main(){
>     item x;
>     cout << x.y <<"\n";
> }

> [ 192 > cat two.C
> struct item {
>     static int y;
> };

> int item::y = 2;

> [ 193 > g++ one.C two.C
> [ 194 > a.out
> 2

> 	For those who only red the first edition of Stroustrup's book
> it is not obvious that "one.C" is invalid,  so it is very suitable to
> report error on this, like Borland C++ does.
Technical Details
Message-ID: <9208291324.AA28807@cygnus.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cygnus.com!mrs

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cygnus.com!mrs
From: mrs@cygnus.com (Mike Stump)
Subject: Re:  Init of static members inside class def
Message-ID: <9208291324.AA28807@cygnus.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Sat, 29 Aug 1992 13:24:50 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 45