Mal*_*chi 1 c enums types compiler-errors
这似乎是一个简单的问题,但我在编译时遇到错误.我希望能够将枚举传递给C中的方法.
枚举
enum TYPES { PHOTON, NEUTRINO, QUARK, PROTON, ELECTRON };
Run Code Online (Sandbox Code Playgroud)
调用方法
makeParticle(PHOTON, 0.3f, 0.09f, location, colour);
Run Code Online (Sandbox Code Playgroud)
方法
struct Particle makeParticle(enum TYPES type, float radius, float speed, struct Vector3 location, struct Vector3 colour)
{
struct Particle p;
p.type = type;
p.radius = radius;
p.speed = speed;
p.location = location;
p.colour = colour;
return p;
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是当我调用方法时:
分配中不兼容的类型
在这个简单的例子中,它对我编译很好:
enum TYPES { PHOTON, NEUTRINO, QUARK, PROTON, ELECTRON };
void makeParticle(enum TYPES type)
{
}
int main(void)
{
makeParticle(PHOTON);
}
Run Code Online (Sandbox Code Playgroud)
你确定你已经TYPES
在代码的定义makeParticle
和调用中声明了可用的声明吗?如果你这样做,它将无法工作:
int main(void)
{
makeParticle(PHOTON);
}
enum TYPES { PHOTON, NEUTRINO, QUARK, PROTON, ELECTRON };
void makeParticle(enum TYPES type)
{
}
Run Code Online (Sandbox Code Playgroud)
因为main()
代码还没有看到TYPES.