Test Foro de elhacker.net SMF 2.1

Programación => Programación C/C++ => Mensaje iniciado por: anamnesis_92 en 28 Octubre 2011, 16:44 PM

Título: [SOLUCIONADO]ERROR AL COMPILAR!
Publicado por: anamnesis_92 en 28 Octubre 2011, 16:44 PM
Buenas, estoy intentando hacer un snake en c y me han saltado estos errores, a ver si me podeis ayudar:
error: expected unqualified-id before 'switch'
y en todos los if : error: expected unqualified-id before 'switch'

#define pantallax 360
#define pantallay 360
#define spritex 16
#define spritey 16

struct serpiente
{

   int d;
   int x;
   int y;
   int fx;
   int fy;


   switch (d)
   {
       case 1:
           fx=x;
           fy=y-spritey;
           break;
       case 2:
           fx=x+spritex;
           fy=y;
           break;
       case 3:
           fx=x;
           fy=y+spritey;
           break;
       case 4:
           fx=x-spritey;
           fy=y;
           break;
   }
   if (fx<0) fx=pantallax-spritex;
   if (fx>(pantallax-spritex)) fx=0;
   if (fy<0) fy=pantallay-spritey;
   if (fy>(pantallay-spritey)) fy=0;


}snake[pantallax*pantallay];


Muchas gracias por adelantado!
Título: Re: ERROR AL COMPILAR!
Publicado por: Pablo Videla en 28 Octubre 2011, 16:45 PM
No creo que sea porque no has inicializado las variables?   :xD
Título: Re: ERROR AL COMPILAR!
Publicado por: naderST en 28 Octubre 2011, 16:49 PM
Es porque lo estas poniendo dentro de una estructura.
Título: Re: ERROR AL COMPILAR!
Publicado por: anamnesis_92 en 28 Octubre 2011, 16:50 PM
si lo hago me sale  error: ISO C++ prohíbe la inicialización del miembro 'd'

EI: juntando mensajes.

solucionado!! muchas gracias
Título: Re: ERROR AL COMPILAR!
Publicado por: Pablo Videla en 28 Octubre 2011, 17:12 PM
Cita de: anamnesis_92 en 28 Octubre 2011, 17:05 PM
solucionado!! muchas gracias

Como lo solucionaste?