I'm writing a simple game and I've recently encountered problem that doesn't seem difficult to solve, however I'm out of ideas.
我正在写一个简单的游戏,最近我遇到了一个看起来并不难解决的问题,但是我没有办法。
in file blocks.c among other functions I've defined a simple function:
在文件块。在其他函数中,我定义了一个简单的函数:
field block_get_field_coordinates(int x, int y)
{
field temp;
temp.x = floor( x / 65 ) * 65 + 15;
temp.y = floor( y / 65) * 65 + 15;
return temp;
}
field is a struct declared in file grid.h
字段是在文件网格中声明的结构。
struct field
{
int x, y;
}f;
typedef struct field field;
And in main.c when I tried the following:
并在主。当我尝试以下的方法:
f = block_get_field_coordinates(blocks[x][y].x4, blocks[x][x].y4);
Where f is 'field' I got an error:
在f 'field'我得到一个错误:
incompatible types when assigning to type 'struct field' from type 'int'
I really don't know what I've done wrong here. Other functions from blocks.c work without throwing out any errors.
我真的不知道我在这里做错了什么。其他功能块。工作时不抛出任何错误。
Interestingly, when I copied just the declaration of struct field, function block_get_field_coordinates into separate file, it worked.
有趣的是,当我仅复制struct字段的声明时,函数block_get_field_坐标转换为单独的文件,它起作用了。
1 个解决方案
#1
4
You need your main to see a declaration of the function.
您需要您的main来查看函数的声明。
e.g. in main
如在主
extern field block_get_field_coordinates(int x, int y);
or better yet put it in block.h as main is going to need the type as well as any functions that use the type.
或者更好的是把它放在一块。h作为main将需要类型以及任何使用类型的函数。
#1
4
You need your main to see a declaration of the function.
您需要您的main来查看函数的声明。
e.g. in main
如在主
extern field block_get_field_coordinates(int x, int y);
or better yet put it in block.h as main is going to need the type as well as any functions that use the type.
或者更好的是把它放在一块。h作为main将需要类型以及任何使用类型的函数。