www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - switch/case problem: 'case must be a string or an integral constant'

reply SirErugor <ontherenth gmail.com> writes:
Hi there :)

I'm just doing a basic switch/case like this:
static final int PONG = 1;
...
input.msgcode = PONG;
...
switch(input.msgcode)
{
     case PONG:
            ....
            break;
}

If I do something like this I get the following error:
"server.d:189: Error: case must be a string or an integral constant, not PONG"

What do I do?

Cheers!
Mar 09 2007
next sibling parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

SirErugor schrieb am 2007-03-09:
 Hi there :)

 I'm just doing a basic switch/case like this:
 static final int PONG = 1;
const int PONG = 1;
 ...
 input.msgcode = PONG;
 ...
 switch(input.msgcode)
 {
      case PONG:
             ....
             break;
 }

 If I do something like this I get the following error:
 "server.d:189: Error: case must be a string or an integral constant, not PONG"

 What do I do?
-----BEGIN PGP SIGNATURE----- iD8DBQFF8VFrLK5blCcjpWoRAhvrAJ4sO0cl2f/OSqJVvL+soITRZCSkrgCfW8y9 bMkJXF4enfdIIHsO+nBjoqU= =yMBi -----END PGP SIGNATURE-----
Mar 09 2007
prev sibling parent Max Samukha <samukha voliacable.com> writes:
On Fri, 09 Mar 2007 06:08:16 -0500, SirErugor <ontherenth gmail.com>
wrote:

Hi there :)

I'm just doing a basic switch/case like this:
static final int PONG = 1;
...
input.msgcode = PONG;
...
switch(input.msgcode)
{
     case PONG:
            ....
            break;
}

If I do something like this I get the following error:
"server.d:189: Error: case must be a string or an integral constant, not PONG"

What do I do?

Cheers!
PONG is not constant. Use 'const' to declare a constant: const int PONG = 1; ''final' is ignored in your example. It is used to make public member functions final: http://www.digitalmars.com/d/function.html
Mar 09 2007