A
army1987
I have two types `eParticleType` and `Particle` defined as
enum eParticleType {
eNull,
eNucleus,
eMuon,
eElectron,
eProton,
eNeutron,
ePhoton,
eNeutrino,
ePion
};
class Particle {
public:
// lots of stuff
private:
eParticleType fType;
// more stuff
};
and a function defined as
std::vector<Particle> PropagateParticle(Particle* input) {
std::vector<Particle> output;
// stuff
switch(fType) {
case eNeutron:
case eProton:
case eNucleus:
output = PropagateNucleus(input);
break;
case eNeutrino:
output = PropagateNeutrino(input);
break;
// etc.
default:
std::cerr << "Unsupported particle type" << std::endl;
abort();
}
// stuff
return output;
}
(Each of the `PropagateXxx` functions has `assert(input->GetType() ==
eXxx;` at the beginning.)
When I compile this with g++, I get "warning: case label value exceeds
maximum value for type", and when I run the program I immediately get
"Assertion `input->GetType() == eMuon' failed.". What's going on? (And
no, I'd rather not have stuff like `class Nucleus: public Particle` etc.
for backward compatibility reasons.)
enum eParticleType {
eNull,
eNucleus,
eMuon,
eElectron,
eProton,
eNeutron,
ePhoton,
eNeutrino,
ePion
};
class Particle {
public:
// lots of stuff
private:
eParticleType fType;
// more stuff
};
and a function defined as
std::vector<Particle> PropagateParticle(Particle* input) {
std::vector<Particle> output;
// stuff
switch(fType) {
case eNeutron:
case eProton:
case eNucleus:
output = PropagateNucleus(input);
break;
case eNeutrino:
output = PropagateNeutrino(input);
break;
// etc.
default:
std::cerr << "Unsupported particle type" << std::endl;
abort();
}
// stuff
return output;
}
(Each of the `PropagateXxx` functions has `assert(input->GetType() ==
eXxx;` at the beginning.)
When I compile this with g++, I get "warning: case label value exceeds
maximum value for type", and when I run the program I immediately get
"Assertion `input->GetType() == eMuon' failed.". What's going on? (And
no, I'd rather not have stuff like `class Nucleus: public Particle` etc.
for backward compatibility reasons.)