Sign in to follow this  

struct error???

This topic is 4113 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm having some problems with a struct definition. I'm using visual c++ express, and the code is as follows: #include "mapADT.h" #include <string.h> #include "d3dx9tex.h" #include "d3dx9.h" #include "d3d9.h" #define TRUE 1 #define FALSE 0 struct tStruct{ LPDIRECT3DSURFACE9 surface; int x_position; int y_position; long graphic; int blocked; int navigable; int mov_dif; int extra; }; typedef struct tStruct tileStruct; struct mapCDT{ char* tiles_path; long map_width; long map_hieght; int num_tiles_x; int num_tiles_y; long tile_width; long tile_hieght; LPDIRECT3DDEVICE9 d3ddev; LPDIRECT3DSURFACE9 tilesSurf; tileStruct** tileMatrix; }; tileStruct** setTileMatrix(mapADT map); LPDIRECT3DSURFACE9 getTiles(char* tile_images, LPDIRECT3DDEVICE9 d3ddev); char* getPath(const char* p); mapADT NewMap(const char* tile_images, int num_tiles_x, int num_tiles_y, long tile_width, long tile_hieght, LPDIRECT3DDEVICE9 d3ddev) { mapADT map; if ((map = malloc(sizeof(mapADT))) == NULL) return NULL; if (((char*)map->tiles_path = (char*)getPath(tile_images)) == NULL) { free(map); return NULL; } map->tile_hieght = tile_hieght; map->tile_width = tile_width; map->num_tiles_x = num_tiles_x; map->num_tiles_y = num_tiles_y; map->map_hieght = (long)num_tiles_y * tile_hieght; map->map_width = num_tiles_x * tile_width; map->d3ddev = d3ddev; map->tilesSurf = (LPDIRECT3DSURFACE9)getTiles(tile_images, d3ddev); if((map->tileMatrix = (tileStruct**)setTileMatrix(map)) == NULL) { //map->tilesSurf->Release(); free(map->tiles_path); free(map); return NULL; } return map; } // Auxiliary functions tileStruct** setTileMatrix(mapADT map) { int i, j, ok; ok = TRUE; tileStruct **ret; /****errorline****/ if((ret = malloc(sizeof(ret)* map->num_tiles_x)) == NULL) return NULL; for(i=0; i<map->num_tiles_x; i++) { if((ret[i]= malloc(sizeof(*ret) * map->num_tiles_y)) == NULL) { ok = FALSE; break; } } if(ok == FALSE && i > 0) { while(--i) free(ret[i]); free(ret); return NULL; } for(i=0; i<map->num_tiles_x; i++) { for(j=0; j<map->num_tiles_y; j++) { ret[i][j].blocked = 0; ret[i][j].extra = 0; ret[i][j].graphic = -1; ret[i][j].mov_dif = 10; ret[i][j].navigable = 0; ret[i][j].surface = NULL; ret[i][j].x_position = i; ret[i][j].y_position = j; } } return ret; } //the error is as follows: /* 1>.\mapADT.c(88) : error C2275: 'tileStruct' : illegal use of this type as an expression 1> .\mapADT.c(22) : see declaration of 'tileStruct' 1>.\mapADT.c(88) : error C2065: 'ret' : undeclared identifier 1>.\mapADT.c(88) : error C2100: illegal indirection */ I don't see where I'm using 'tileStruct' as an expression!!!

Share this post


Link to post
Share on other sites
In C, all variable declarations must come at the top of a block (i.e., they must be the first things in a given scope, such as a function). You need to move
tileStruct **ret;
to come before
ok = TRUE;

Share this post


Link to post
Share on other sites
0) source code goes between either [code][/code] or [source][/source] tags depending on length, please.

1) Why are you writing C code?

2) Why are you using a C++ compiler for C code?

Share this post


Link to post
Share on other sites

This topic is 4113 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this