Topic: Is this legal C++...?


Author: "Omry Yadan" <omry_y@inter.net.il>
Date: 1999/04/02
Raw View
Paul wrote in message <3700171e.20484763@news.ccnet.com>...
>   struct X{
>      static const int x=0;
>   };
>
>While some compilers reject this, the standard seems to suggest
>that it is legal. See std. sec 9.4.4 and 3.1.

its legal, but meny compilers does not support it yet.
a better alternative might be :
struct X
{
    enum {x = 0};
};


--
   Omry Yadan.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: paulp.removethis@ccnet.com (Paul)
Date: 1999/03/30
Raw View
   struct X{
      static const int x=0;
   };

While some compilers reject this, the standard seems to suggest
that it is legal. See std. sec 9.4.4 and 3.1.

Paul
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/03/30
Raw View
Paul wrote:
>
>    struct X{
>       static const int x=0;
>    };
>
> While some compilers reject this, the standard seems to suggest
> that it is legal. See std. sec 9.4.4 and 3.1.

Yes, it's perfectly legal for constants of integral type (like int).
Note that you also have to define X::x once in your program:

const int X::x;

--

Valentin Bonnard
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]