2011-08-05 22 views
5

que estoy tratando de hacer esto:tipo de matriz tiene incompleta elemento de tipo

typedef struct { 
    float x; 
    float y; 
} coords; 
struct coords texCoordinates[] = { {420, 120}, {420, 180}}; 

Sin embargo, el compilador no me deja. :?! (¿Qué hay de malo en esta declaración Gracias por su ayuda

Respuesta

14

sea porque:


typedef struct { 
    float x; 
    float y; 
} coords; 
coords texCoordinates[] = { {420, 120}, {420, 180}}; 

O


struct coords { 
    float x; 
    float y; 
}; 
struct coords texCoordinates[] = { {420, 120}, {420, 180}}; 

En C, struct nombres residen en un espacio de nombres diferente que typedef s.

Por supuesto, también puede usar typedef struct coords { float x; float y; } coords; y usar struct coords o coords. En este caso, no importará lo que elija, pero para las estructuras de autorreferencia, necesita un nombre de estructura:

struct list_node { 
    struct list_node* next; // reference this structure type - need struct name  
    void * val; 
}; 
Cuestiones relacionadas