Declaring constants within the scope of a class

From: Generic Usenet Account (usenet_at_sta.samsung.com)
Date: 03/15/05


Date: 15 Mar 2005 08:11:13 -0800

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



Relevant Pages

  • Re: C++ to VB conversion and preprocessor definition
    ... The #define preprocessor definition tells the compiler to effectively ... perform a search and replace on the sourcecode as it is compiling, replacing ...
    (microsoft.public.dotnet.languages.vb)
  • Re: class that inherits a collection
    ... When I compile my code with a single declaration of a node object in ... you should be able to add the correct using directive -- "using System.Collections.ObjectModel;" -- to your source code file and get the compiler error to go away. ... an interface, and as such a class that is declared as implementing that interface does in fact have to implement everything in the interface. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: breakpoint will not currently be hit
    ... It stopped the compiler error, ... The solution actually has several projects - I can set a breakpoint in the startup project and it gets hit. ... There is one that is interesting, as it suggests a reason why VB compiler might crash. ... windows forms application. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: ByRef not returning changes to passed arguments
    ... I intentionally cooked up sample code to simplify the presentation ... ... What I said about getting a compiler error on line 05 bothered me (I use ... public myfunction(byref data as variant) as boolean ...
    (microsoft.public.excel)
  • Re: Difference between passing a number and a variable to a subroutine
    ... i get a compiler error: ... subroutine for this generic subroutine call. ... Thus it is an integer array of kind hsize_t. ... The compiler will convert the kind for you here, ...
    (comp.lang.fortran)