Ayuda Struct

Iniciado por BlackM4ster, 7 Abril 2013, 18:31 PM

0 Miembros y 1 Visitante están viendo este tema.

BlackM4ster

Hola, estoy intentando hacer una estructura sencilla para usar dentro de otra, son estas:
struct Objeto{

Bounding bounding;
   float x, y, z;};

y en otra cabecera:
struct Bounding {

int Tipo; // 1 -> Esfera // 2 -> Box alineada a los ejes // 3 -> Box alineada al objeto

float xmax, xmin;
float ymax, ymin;
float zmax, zmin;
float r;

float vx[8], vy[8], vz[8];

void Crear(int tipo, GLuint objeto);
};


Pero no se porque me dice:
1>e:\c++\opengl\movimiento de pj + camara\juego1\idobjeto.h(12) : error C2146: error de sintaxis : falta ';' delante del identificador 'bounding'

y si en vez de Bounding bounding; pongo struct Bounding bounding;
error C2079: 'Objeto::bounding' utiliza struct 'Bounding' sin definir

Ayuda rapida porfavor
- Pásate por mi web -
https://codeisc.com

rir3760

¿Por favor puedes publicar el código fuente completo (por supuesto si no es muy largo)?

Con esos dos fragmentos lo único que se me ocurre es que revises el orden de las declaraciones (la declaración de "Bounding" debe encontrarse antes de la de "Objeto").

Un saludo
C retains the basic philosophy that programmers know what they are doing; it only requires that they state their intentions explicitly.
--
Kernighan & Ritchie, The C programming language

BlackM4ster

a ver son 2 headers, cada 1 con su estrctura:
objetos.h
#include "Bounding.h"
struct Objeto{

struct Bounding bounding;
   float x, y, z;
   int modelo;
   float t_x, t_y, t_z;
   float r;
   int ang_x;
   bool g, c, usado;

   void Nuevo(int vmodelo, float vx,float vy,float vz,int vang_x,float vt_x,float vt_y,float vt_z, bool vg, bool vc) {
      modelo = vmodelo;
      ang_x = vang_x;
      x = vx;   t_x = vt_x;
      y = vy;   t_y = vt_y;
      z = vz;   t_z = vt_z;

  r = (t_x+t_y+t_z)/6;

  g = vg; c = vc;
  usado = true;
      ObjetosTotales++;
   }

   void PintarBoundingSphere(){

GLUquadricObj *q;
q=gluNewQuadric();
gluQuadricDrawStyle(q, GLU_SILHOUETTE);
gluQuadricNormals(q, GLU_SMOOTH);
gluQuadricTexture(q, GL_FALSE);
gluSphere(q,r+r/2,16,16);
gluDeleteQuadric(q);

   }
};


y la Bounding.h
#include "idobjeto.h"
struct Bounding {

int Tipo; // 1 -> Esfera // 2 -> Box alineada a los ejes // 3 -> Box alineada al objeto

float xmax, xmin;
float ymax, ymin;
float zmax, zmin;
float r;

float vx[8], vy[8], vz[8];

void Crear(int tipo, GLuint objeto);
};


eso es no más
- Pásate por mi web -
https://codeisc.com

rir3760

Te falto uno: "Objeto.h" incluye a "Bounding.h" y este a "idobjeto.h".

Un saludo
C retains the basic philosophy that programmers know what they are doing; it only requires that they state their intentions explicitly.
--
Kernighan & Ritchie, The C programming language

BlackM4ster

Uups "Objeto.h" = "idobjeto.h" esque lo habia cambiado para el ejemplo.
De por si está bien incluido  :-[
- Pásate por mi web -
https://codeisc.com

rir3760

Déjame ver si entiendo correctamente:

1) El primer archivo se llama "Objeto.h" y su primera linea es:
#include "Bounding.h"

2) El segundo archivo se llama "Bounding.h" y su primera linea es:
#include "Objeto.h"

Si es así el problema es una dependencia circular: no puedes tener dos archivos donde cada uno incluya al otro.

Un saludo
C retains the basic philosophy that programmers know what they are doing; it only requires that they state their intentions explicitly.
--
Kernighan & Ritchie, The C programming language

BlackM4ster

mm si quito la primera linea de bounding sigue fallando
- Pásate por mi web -
https://codeisc.com

rir3760

Revisando con cuidado utilizas la variable "ObjetosTotales" pero no la declaras en ninguno de los dos archivos.

Mejor publica el código fuente completo junto con las actualizaciones que hayas realizado.

Un saludo
C retains the basic philosophy that programmers know what they are doing; it only requires that they state their intentions explicitly.
--
Kernighan & Ritchie, The C programming language

BlackM4ster

- Pásate por mi web -
https://codeisc.com

avesudra

Quizás es lo que tu dices rir3760 lo de la referencia circular.
En Pj.h
#include "IdObjeto.h"
#include "Includes.h"

En idObjeto.h
#include "Includes.h"
#include "Bounding.h"

En Bounding.h
#include "Includes.h"
#pragma once
#include "Pj.h"

Yo que tú metería en  Includes.h esto:
#include "Bounding.h"
#include "Pj.h"
#include "idObjeto.h"

Y dejaría a los demás con la cabecera Includes.h únicamente, prueba tu porque yo no tengo OpenGL instalado. Creo que es una referencia circular dado que bounding incluye a pj y pj incluye a idObjeto que incluye a pj y así sucesivamente ...
Regístrate en