Jump to content
  • Advertisement
Sign in to follow this  
ninuxw

struct error???

This topic is 4322 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= malloc(sizeof(*ret) * map->num_tiles_y)) == NULL) { ok = FALSE; break; } } if(ok == FALSE && i > 0) { while(--i) free(ret); free(ret); return NULL; } for(i=0; i<map->num_tiles_x; i++) { for(j=0; j<map->num_tiles_y; j++) { ret[j].blocked = 0; ret[j].extra = 0; ret[j].graphic = -1; ret[j].mov_dif = 10; ret[j].navigable = 0; ret[j].surface = NULL; ret[j].x_position = i; ret[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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!