Mail Archives: djgpp/1999/05/23/21:55:17
From: | "Anthony Borla" <ajborla AT bigpond DOT com>
|
Subject: | Re: Help : warning invalid initializer
|
Newsgroups: | comp.os.msdos.djgpp,comp.lang.c++
|
References: | <374898C3 DOT AD7EB7FC AT netvigator DOT com>
|
Message-ID: | <01bea580$c43ecec0$0600a8c0@win95002.domain192>
|
X-Newsreader: | Microsoft Internet News 4.70.1161
|
Lines: | 75
|
Date: | Mon, 24 May 1999 00:57:15 GMT
|
NNTP-Posting-Host: | 139.134.108.162
|
X-Trace: | newsfeeds.bigpond.com 927507435 139.134.108.162 (Mon, 24 May 1999 10:57:15 EST)
|
NNTP-Posting-Date: | Mon, 24 May 1999 10:57:15 EST
|
Organization: | Telstra BigPond Internet Services (http://www.bigpond.com)
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
NG Chi Fai <cfng1 AT netvigator DOT com> wrote in article
<374898C3 DOT AD7EB7FC AT netvigator DOT com>...
> Hello all,
>
> I encountered the below problem with my code listed below. But I have no
> idea of what does it mean by "invalid initializer"
>
> egcs1.1.2 (DJGPP) warning message:
> IOTable.hpp:11: ANSI C++ forbids in-class initialization of non-const
> static member `IOTableIdentifiers'
> IOTable.hpp:11: invalid initializer
>
> -- source code IOTable.hpp --
> #ifndef __CF_CLASSIOTABLE__
> #define __CF_CLASSIOTABLE__
> // ... some #include here
>
> class IOTable
> {
> private:
> static const char*
>
IOTableIdentifiers[]={"A","B","C","D","E","F,"G","H","I","J","K","L","M","N"
,"O","P",NULL};
> // line 11
> static const char* const IdentifierSuffix="_S";
> // ... lines follows
> };
>
> Thanks in advance.
>
> NG Chi Fai
>
Hi,
The use of the 'static' keyword in a class data member declaration only
makes it a class member; it does not allocate storage to it. Therefore, you
cannot initialise such a member within the class definition. You must:
* Declare a seperate variable to provide the required storage
* Initialise it at declaration time
The example below shows how:
// Class Definition
class IOTable
{
private:
static const char* IOTableIdentifiers[];
// line 11
static const char* const IdentifierSuffix[];
// ... lines follows
};
// Initialise static
const char* IOTable::IOTableIdentifiers[] =
{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",0};
const char* const IOTable::IdentifierSuffix[] = {"_","S",0};
int main(void)
{
IOTable iotbl;
return 0;
}
By the way, you are missing a double quote character after the 'F' in:
>
IOTableIdentifiers[]={"A","B","C","D","E","F,"G","H","I","J","K","L","M","N"
,"O","P",NULL};
^
|
- Raw text -