문제
이것은 간단한 질문처럼 보일 수 있지만 이것을 컴파일 할 때 오류가 발생합니다. 나는 열거를 C의 방법으로 전달할 수 있기를 원한다.
열거적
enum TYPES { PHOTON, NEUTRINO, QUARK, PROTON, ELECTRON };
방법을 호출합니다
makeParticle(PHOTON, 0.3f, 0.09f, location, colour);
방법
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;
}
내가 얻는 오류는 메소드를 호출 할 때입니다.
과제에서 호환되지 않는 유형
해결책
이 컷 다운 예에서 나에게 잘 컴파일합니다.
enum TYPES { PHOTON, NEUTRINO, QUARK, PROTON, ELECTRON };
void makeParticle(enum TYPES type)
{
}
int main(void)
{
makeParticle(PHOTON);
}
당신은 당신이 선언을했다고 확신합니까? TYPES
두 정의에서 코드에 사용할 수 있습니다 makeParticle
그리고 그것에 대한 부름? 이렇게하면 작동하지 않습니다.
int main(void)
{
makeParticle(PHOTON);
}
enum TYPES { PHOTON, NEUTRINO, QUARK, PROTON, ELECTRON };
void makeParticle(enum TYPES type)
{
}
때문에 main()
코드는 아직 유형을 보지 못했습니다.
다른 팁
변경해보십시오
p.type = type;
에게
p.type = (int)type;
도움이되지 않으면 정의를 포함하여 전체 .C 파일을 추가하십시오. struct Particle
당신의 질문에.
제휴하지 않습니다 StackOverflow