Re: Declaring constants within the scope of a class

From: Shezan Baig (shezanbaig2004_at_gmail.com)
Date: 03/15/05


Date: 15 Mar 2005 08:17:28 -0800


Generic Usenet Account wrote:
> I am trying to compile the following sample code:
>
> class WhatISHappeningHere
> {
> static const int x = 32;
> static const char* yy = "Howdy";
> // ...
> // blah blah blah
> // ...
> };
>
>
> My GCC compiler (g++ version 2.95.2) is giving the following
misleading
> compiler error:
>
> ANSI C++ forbids in-class initialization of non-const static member
> `yy'
>
>
> I suspect that initialization of static data members that are not of
an
> integral type is not allowed in C++, but the compiler is giving a
wrong
> error message. Kindly confirm/refute my observation.
>
> Thanks,
> Gus

I'm not sure if this will work, but try:

static const char* const yy = "Howdy";



Relevant Pages

  • Re: Check for null object
    ... I suspect you are getting a compiler error telling you that the ... This doesnt work. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Newb question
    ... As far as the compiler is concerned if the initialization code is not ... This should do the trick and will not give the compiler error. ... > I am learning C# and I get a compilerer error below, ... > class TestApp ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Newb question
    ... Madhuschreef: ... you have declared the variable but the initialization happens ... > This should do the trick and will not give the compiler error. ... didn't know I could use TestClass jo = null; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: COBOL Error Message Assist (MVS)
    ... system is MVS, ... :>IGYAS5125-U THE COMPILATION WAS TERMINATED DUE TO A COMPILER ERROR IN ... :>PHASE ID: "IGYCASM1". ... I suspect it may have something ...
    (comp.lang.cobol)