G4ParticleChange compilation errors

Hello,

I have a class to limit the global time of a track (geant4-11.1), as follows:

Code snippet
class TrackTimeLimiter : public G4VProcess {
	G4double maxTime;
	G4double limit;
	class ParticleChange : public G4ParticleChange {
	public:
	  ParticleChange() : G4ParticleChange() { }
	};
	ParticleChange change;
public:
	TrackTimeLimiter(double _maxTime) : 
			G4VProcess("TrackTimeLimiter",fUserDefined), change() {
		maxTime = _maxTime;
		limit = 0.0;
	}

	G4VProcess *clone() { return new TrackTimeLimiter(*this); }
...
}

However, errors occur when compiling with geant4-11.1. Could you please take a look and figure out the problem?

Compilation errors
/home/g4bl/BLCMDphysics.cc: In member function ‚ÄėG4VProcess* TrackTimeLimiter::clone()‚Äô:
/home/g4bl/BLCMDphysics.cc:154:57: error: use of deleted function ‚ÄėTrackTimeLimiter::TrackTimeLimiter(const TrackTimeLimiter&)‚Äô
  154 |  G4VProcess *clone() { return new TrackTimeLimiter(*this); }
      |                                                         ^
/home/g4bl/BLCMDphysics.cc:139:7: note: ‚ÄėTrackTimeLimiter::TrackTimeLimiter(const TrackTimeLimiter&)‚Äô is implicitly deleted because the default definition would be ill-formed:
  139 | class TrackTimeLimiter : public G4VProcess {
      |       ^~~~~~~~~~~~~~~~
/home/g4bl/BLCMDphysics.cc:139:7: error: use of deleted function ‚ÄėTrackTimeLimiter::ParticleChange::ParticleChange(const TrackTimeLimiter::ParticleChange&)‚Äô
/home/g4bl/BLCMDphysics.cc:142:8: note: ‚ÄėTrackTimeLimiter::ParticleChange::ParticleChange(const TrackTimeLimiter::ParticleChange&)‚Äô is implicitly deleted because the default definition would be ill-formed:
  142 |  class ParticleChange : public G4ParticleChange {
      |        ^~~~~~~~~~~~~~
/home/g4bl/BLCMDphysics.cc:142:8: error: use of deleted function ‚ÄėG4ParticleChange::G4ParticleChange(const G4ParticleChange&)‚Äô
In file included from /home/geant4-11.1.0-gcc9.3-c++17/include/Geant4/G4VProcess.hh:51,
                 from /home/geant4-11.1.0-gcc9.3-c++17/include/Geant4/G4VContinuousDiscreteProcess.hh:43,
                 from /home/geant4-11.1.0-gcc9.3-c++17/include/Geant4/G4VEnergyLossProcess.hh:54,
                 from /home/geant4-11.1.0-gcc9.3-c++17/include/Geant4/G4MuIonisation.hh:76,
                 from /home/g4bl/BLCMDphysics.cc:23:
/home/geant4-11.1.0-gcc9.3-c++17/include/Geant4/G4ParticleChange.hh:65:5: note: declared here
   65 |     G4ParticleChange(const G4ParticleChange& right) = delete;
      |     ^~~~~~~~~~~~~~~~

Thanks,
Y

From 11.1, G4VParticleChange and concrete classes thereof have copy constructors and copy assignment operators marked as delete. This was done as these classes are intended to be owned per-process (@civanch can comment better), and processes are not copied.

The workaround in this case would be to hold the custom ParticleChange as a raw pointer, or better std::unique_ptr<ParticleChange>.

1 Like