switch/case problem: 'case must be a string or an integral constant'

Max Samukha samukha at voliacable.com
Fri Mar 9 03:50:54 PST 2007


On Fri, 09 Mar 2007 06:08:16 -0500, SirErugor <ontherenth at 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


More information about the Digitalmars-d-learn mailing list