Skip to content
Snippets Groups Projects
Commit edd06708 authored by Rene Brun's avatar Rene Brun
Browse files

Correct implementation of the copy constructor and assignment operator

git-svn-id: http://root.cern.ch/svn/root/trunk@31827 27541ba8-7e3a-0410-8455-c3a389f83636
parent 37e9274e
No related branches found
No related tags found
No related merge requests found
...@@ -120,7 +120,12 @@ TTask& TTask::operator=(const TTask& tt) ...@@ -120,7 +120,12 @@ TTask& TTask::operator=(const TTask& tt)
//assignment operator (PLEASE DO NOT USE THIS IS WRONG) //assignment operator (PLEASE DO NOT USE THIS IS WRONG)
if(this!=&tt) { if(this!=&tt) {
TNamed::operator=(tt); TNamed::operator=(tt);
fTasks= 0; //<===tobe fixed fTasks->Delete();
TIter next(tt.fTasks);
TTask *task;
while ((task = (TTask*)next())) {
fTasks->Add(new TTask(*task));
}
fOption=tt.fOption; fOption=tt.fOption;
fBreakin=tt.fBreakin; fBreakin=tt.fBreakin;
fBreakout=tt.fBreakout; fBreakout=tt.fBreakout;
...@@ -131,17 +136,26 @@ TTask& TTask::operator=(const TTask& tt) ...@@ -131,17 +136,26 @@ TTask& TTask::operator=(const TTask& tt)
} }
//______________________________________________________________________________ //______________________________________________________________________________ //______________________________________________________________________________ //______________________________________________________________________________
TTask::TTask(const TTask &task) : TNamed(task) TTask::TTask(const TTask &other) : TNamed(other)
{ {
// Copy constructors. (PLEASE DO NOT USE THIS IS WRONG) // Copy constructor.
fTasks = new TList(); fTasks = new TList();
TIter next(other.fTasks);
TTask *task;
while ((task = (TTask*)next())) {
fTasks->Add(new TTask(*task));
}
fOption = other.fOption;
fBreakin = other.fBreakin;
fBreakout = other.fBreakout;
fHasExecuted = kFALSE;
fActive = other.fActive;
} }
//______________________________________________________________________________ //______________________________________________________________________________
TTask::~TTask() TTask::~TTask()
{ {
// Delete a task and its subtasks. // Delete a task and its subtasks.
if (!fTasks) return; if (!fTasks) return;
fTasks->Delete(); fTasks->Delete();
delete fTasks; delete fTasks;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment