geant 4/c++ [closed]中的“do”和“while”之前应为未限定的ID

vfhzx4xs  于 2023-03-14  发布在  其他
关注(0)|答案(1)|浏览(202)

**已关闭。**此问题为not reproducible or was caused by typos。当前不接受答案。

这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
53分钟前就关门了。
Improve this question
我收到以下错误消息:

error: expected unqualified-id before ‘do’
do
^~
error: expected unqualified-id before ‘while’
} while(!extravasation->Inside(point) && ++itry < maxtries);
  ^~~~~

对于此代码:

void PrimaryGeneratorAction::GeneratePrimaries(G4Event *anEvent)
  {G4ParticleDefinition \*particle = fParticleGun->GetParticleDefinition();
if (particle == G4ChargedGeantino::ChargedGeantino())
  {
G4int Z=9;
G4int A=18;
G4double charge = 0.*eplus;
G4double energy = 0.*keV;
G4ParticleDefinition *ion = G4IonTable::GetIonTable()->GetIon(Z, A, energy);

fParticleGun->SetParticleDefinition(ion);
fParticleGun->SetParticleCharge(charge);
fParticleGun->SetParticlePosition(point);
                 }
         }

do
 {
point.set(xlo + G4UniformRand()*(xhi-xlo),ylo + G4UniformRand()*(yhi-ylo),zlo + G4UniformRand()*(zhi-zlo));
fParticleGun->GeneratePrimaryVertex(anEvent);
while(!extravasation->Inside(point) && ++itry < maxtries);

我试过添加和删除分号、添加新行和各种其他更改来尝试使其工作,但我觉得我可能在语法中的某个地方遗漏了一些小东西,使其无法工作
任何帮助都是非常感谢!

wwtsj6pe

wwtsj6pe1#

你应该在职业生涯的 * 早期 * 学会使用 sane 代码格式,这使得问题变得非常明显:

void PrimaryGeneratorAction::GeneratePrimaries(G4Event *anEvent)
{
    G4ParticleDefinition \*particle = fParticleGun->GetParticleDefinition();
    if (particle == G4ChargedGeantino::ChargedGeantino())
    {
        G4int Z=9;
        G4int A=18;
        G4double charge = 0.*eplus;
        G4double energy = 0.*keV;
        G4ParticleDefinition *ion = G4IonTable::GetIonTable()->GetIon(Z, A, energy);

        fParticleGun->SetParticleDefinition(ion);
        fParticleGun->SetParticleCharge(charge);
        fParticleGun->SetParticlePosition(point);
    }
}
// ^ this bracket closes the function GeneratePrimaries

// Now this "do" clause is dangling (not inside a function)
do
{
    point.set(xlo + G4UniformRand()*(xhi-xlo),ylo + G4UniformRand()*(yhi-ylo),zlo + G4UniformRand()*(zhi-zlo));
    fParticleGun->GeneratePrimaryVertex(anEvent);
// ^ missing a closing brace here
while(!extravasation->Inside(point) && ++itry < maxtries);

相关问题