Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   C++ Builder (https://www.clubdelphi.com/foros/forumdisplay.php?f=13)
-   -   duda juego c++ builder 2007 (https://www.clubdelphi.com/foros/showthread.php?t=63866)

torrescrack9 06-03-2009 00:05:39

duda juego c++ builder 2007
 
Estoy haciendo el juego de simon dice en c++ builder 2007 y tengo la siguiente duda debo dimensionar un vector y he probado de un monton de formas y no soi capaz me da un error....

Mira pongo el codigo aver si alguien sabe a q se debe el error...

Lo que kiero es dimensionar las variables vector y vectorentrada

El error que me sale es el siguiente:

Cita:

---structure required on left side of. or .

--- invalid direction
Código:

#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
int repeticiones;
int contador;
short vector;
short vectorentrada;
int i;
const short limiteinf=1;
const short limitesup=4;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
void colores_iniciales()
 {
  Form2->I_1->Picture=Form2->I_gris1->Picture;
  Form2->I_2->Picture=Form2->I_gris2->Picture;
  Form2->I_3->Picture=Form2->I_gris3->Picture;
  Form2->I_4->Picture=Form2->I_gris4->Picture;
 }
void aleatorio(short limiteinf,short limitesup)
 {
  short aleatorio=0;
  Randomize();
  aleatorio=Int((limitesup-limiteinf+1)*Random()+limiteinf);
 }
void inicio()
{
 //int i;
 vector.redim(repeticiones);
 vectorentrada.redim(repeticiones);
 for(i=1;i<repeticiones;i++)
 {
  vector[i] = aleatorio(limiteinf,limitesup);
 }
 Form2->I_1->Enabled=false;
 Form2->I_2->Enabled=false;
 Form2->I_3->Enabled=false;
 Form2->I_4->Enabled=false;
 Form2->Juego1->Enabled=false;
 Form2->Acerca1->Enabled=false;
 Form2->Secuenciador->Enabled=true;
 contador=1;
}
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
 : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormShow(TObject *Sender)
{
colores_iniciales();
repeticiones=1;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Nuevo1Click(TObject *Sender)
{
inicio();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::SecuenciadorTimer(TObject *Sender)
{
colores_iniciales();
if(contador<=repeticiones)
 {
  L_Contador->Caption=contador;
  switch((vector[contador]))
  {
    case 1:
      I_1->Picture=I_rojo->Picture;
      break;
    case 2:
      I_2->Picture=I_azul->Picture;
      break;
    case 3:
      I_3->Picture=I_Amarillo->Picture;
      break;
    case 4:
      I_4->Picture=I_Verde->Picture;
      break;
  }  // fin switch;
  contador=contador+1;
  }
else  {
  L_Contador->Caption="";
  contador=1;
  Secuenciador->Enabled=false;
  I_1->Enabled=true;
  I_2->Enabled=true;
  I_3->Enabled=true;
  I_4->Enabled=true;
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm2::BorradorTimer(TObject *Sender)
{
colores_iniciales();
Borrador->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Salir1Click(TObject *Sender)
{
Form2->Close();
}
//---------------------------------------------------------------------------


escafandra 06-03-2009 00:40:33

Cita:

Empezado por torrescrack9 (Mensaje 340363)
debo dimensionar un vector y he probado de un monton de formas y no soi capaz me da un error....
Código:

short vector;
short vectorentrada;
..........
..........
vector.redim(repeticiones);
vectorentrada.redim(repeticiones);

El error que me sale es el siguiente:
---structure required on left side of. or .
--- invalid direction

Pues un short no es una clase y no tiene un miembro que se llame redim, por lo tanto no te compila.

Imagino que lo que quieres es usar el template vector asi:

Código:

#include <vector>
...
...
std::vector<short> Vector(repeticiones);
std::vector<short> VectorEntrada(repeticiones);

Saludos.

torrescrack9 06-03-2009 14:52:26

he probado con eso que me as puesto y me sigue saliendo un error en la funcion inicio:
el otro error de dimensionar el vector ya creo q lo e solucionado xq no me salen errores

Código:

void inicio()
{
//int i;
std::vector<short> Vector(repeticiones);
std::vector<short> VectorEntrada(repeticiones);
for(i=1;i<repeticiones;i++)
{
/// aki me da el error siguiente: invalid direction
vector[i] = aleatorio(limiteinf,limitesup);
}
Form2->I_1->Enabled=false;
Form2->I_2->Enabled=false;
Form2->I_3->Enabled=false;
Form2->I_4->Enabled=false;
Form2->Juego1->Enabled=false;
Form2->Acerca1->Enabled=false;
Form2->Secuenciador->Enabled=true;
contador=1;
}


escafandra 06-03-2009 16:17:40

el template se llama vector, por eso te cambié los nombres a Vector y VectorEntrada. C y C++ son sensibles a mayúsculas, esto quiere decir que vector y Vector no es lo mismo.

...así que cambia tu variable vector a Vector y vectorentrada a VectorEntrada. Esta última no hace falta, pero la camibé por estética y congruencia sintáctica con su "hermana" :rolleyes:

Saludos.

torrescrack9 07-03-2009 02:10:46

weno lo e intentao pro no lo consigo me sigue saliendo el mismo error que antes....
mira voi a poner el codigo dnd me da el fallo aver si sq tngo algo mal inicializado o mal escrito o algo.....

CODIGO VARIABLES
#include <vcl.h>
#pragma hdrstop
#include <Vector>
#include "Unit2.h"

int repeticiones;
int contador;
int Vector;
int i;
const short limiteinf=1;
const short limitesup=4;



CODIGO FUNCION

void inicio()
{
//int i;
std::vector<short> Vector(repeticiones);
std::vector<short> VectorEntrada(repeticiones);
//vector.redim(repeticiones);
//vectorentrada.redim(repeticiones);
for(i=1;i<repeticiones;i++)
{
Vector[i]=aleatorio(limiteinf,limitesup); // En esta linea es dnd me da el siguiente error: "Not an allowed type" y "Undefined symbol 'vector'"
}
Form2->I_1->Enabled=false;
Form2->I_2->Enabled=false;
Form2->I_3->Enabled=false;
Form2->I_4->Enabled=false;
Form2->Juego1->Enabled=false;
Form2->Acerca1->Enabled=false;
Form2->Secuenciador->Enabled=true;
contador=1;
}

escafandra 07-03-2009 23:51:37

Código:

#include <vcl.h>
#pragma hdrstop
#include <Vector>
#include "Unit2.h"

int repeticiones;
int contador;
// int Vector;  Vector no es un entero, es un template que inicializas en inicio
int i;
const short limiteinf=1;
const short limitesup=4;

 
 
CODIGO FUNCION
 
void inicio()
{
 //int i;
 std::vector<short> Vector(repeticiones);
 std::vector<short> VectorEntrada(repeticiones);
 //vector.redim(repeticiones);  // redim no es miembro del template vector
 //vectorentrada.redim(repeticiones);
 for(i=1;i<repeticiones;i++)
 {
  Vector[i]=aleatorio(limiteinf,limitesup); // En esta linea es dnd me da el    siguiente error: "Not an allowed type" y "Undefined symbol 'vector'"
  // El error es porque lo declaraste antes como int
 }
 ......
......
}

Saludos


La franja horaria es GMT +2. Ahora son las 20:40:43.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi