我正在製作一個C程序,它需要訪問結構中的結構數組。無法訪問結構數組中的成員變量結構
定義看起來像下面
在主函數struct def_world
{
bool lock;
char tilemap;
def_tile tile[100][100];
struct def_tile
{
bool lock;
char kind;
def_obj * obj;
void * evt;
};
struct def_obj
{
bool lock;
int indexOfTable;
bool frozen;
char x,y;
char kind;
char face;
char * msg;
char * ip;
};
,我想訪問世界tile[3][3]
的OBJ的臉。
我初始化世界
def_world world={0,};
但以下行犯錯誤
world.tile[3][3].obj=newobj();//newobj() returns def_obj type
world.tile[3][3].obj->face;
任何想法如何訪問OBJ的臉?
至少要顯示'newobj()'的聲明,知道它是否返回一個'def_obj'對象或一個'def_obj *'指向'def_obj'的指針是很重要的。實際上,爲什麼不發佈一個能夠產生錯誤的可編輯示例 - 它不應該比現在更多,但它不需要人們猜測拼寫錯誤(請使用copy-n-paste - 不要在SO編輯框中重新輸入)。 –
使用VS2010對我來說很好(並且顛倒了結構的聲明順序)。另外,這是C++不是C,C中沒有'bool'。也許'newobj'被定義爲'def_obj newobj()'而不是'def_obj * newobj()'? – Skizz
的事情是,我的VS2010說,當我剛剛完成鍵入world.tile [3] [3]有什麼錯誤嗎? –