关于Vector<>和interator中的无效转换问题.

本人在使用GEANT4模拟,以下为部分相关程序.目的是获得次级粒子的能量等信息,当gamma被kill或stop后,开始追踪次级粒子,并加以筛选获得输出文件.然而在编译的时候出现了以下报错:**error: invalid conversion from ‘const G4TrackVector* {aka const std::vector}’ to ‘G4TrackVector {aka std::vector}’ [-fpermissive]
G4TrackVector
fpTrackVector = fStep->GetSecondary(); **
^
求各位帮我看看,感激不尽呀,由于金币不足,待日后补齐各位热心人.****

//do the calculation of energy deposition

G4TrackVector* fpTrackVector = fStep->GetSecondary();
G4TrackStatus TrackStatus = fTrack->GetTrackStatus();
if ( particle == "neutron" && TrackStatus == fStopAndKill ){

        G4int i;
        vector <G4Track*>::const_iterator itr;
        G4int tv_size = fpTrackVector->size ();
        itr = fpTrackVector->begin ();
        if( tv_size )
        {
            for ( i=0;i<tv_size;i++){ //why not "<="?
                G4Track* secondaryTrack = *(itr+i);

                G4double sec_x = secondaryTrack->GetPosition().x()/mm;
                G4double sec_y = secondaryTrack->GetPosition().y()/mm;
                G4double sec_z = secondaryTrack->GetPosition().z()/mm;

                G4String sec_name = secondaryTrack->GetDefinition()->GetParticleName();
                G4String sec_volume = secondaryTrack->GetVolume()->GetName();
                G4double sec_kineticEnergy = secondaryTrack->GetKineticEnergy()/MeV;
                G4double sec_totalEnergy = secondaryTrack->GetTotalEnergy()/MeV;
                G4String sec_process = secondaryTrack->GetProcessName();

                if( sec_volume == "Scatter" && sec_name == "alpha" ){
                  G4int SL = sec_name.size( );
                    //fUserDataFile->func();
                    fUserDataFile->AddElectronInitial ( eventNum, SL, sec_name, sec_x, sec_y, sec_z, sec_kineticEnergy );
                //fUserDataFile->func();
                //G4cout << "step!" << G4endl;  */
            }

          }

        }

}

1个回答

G4TrackVector* fpTrackVector = fStep->GetSecondary();
看编译错误,是这句话的问题,能把GetSecondary()方法的代码贴下么?GetSecondary()函数是不是返回的是const类型的vector指针,
改成const G4TrackVector* fpTrackVector = fStep->GetSecondary(); 试试

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问