Changed destructor to Dispose()

Der der Destruktor auch aufgerufen wird, wenn eine lokale Instanz
gelöscht wird (z.B. in primImplikantenAt()), verlieren wir unsere
PrimImplikanten zu früh. Mit Dispose() können wir das selbst und nur
ganz am Ende machen.
This commit is contained in:
Jonny007-MKD 2013-11-21 21:05:03 +01:00
parent fabe226ce6
commit 3bf1e178a8
3 changed files with 14 additions and 9 deletions

View File

@ -1,4 +1,4 @@
// Hazard.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
// Hazard.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//
#include "stdafx.h"
@ -97,9 +97,9 @@ int _tmain(int argc, _TCHAR* argv[])
// find hazards
if (numOnes > numElements / 2) // we have more 1 than 0 --> checkerboard --> 50% of cells are checked
{
cout << "\nSchachbrettmuster\n";
for (uint i = 0; i < numElements; i++)
{
cout << "\nSchachbrettmuster\n";
uint grayI = i ^ (i/2); // transform to gray code
vector<Cell*> hazardousNeighbors = cells[grayI]->GetHazards();
@ -115,9 +115,9 @@ int _tmain(int argc, _TCHAR* argv[])
}
else // less 1 than 0 --> only check every 1 --> less than 50% (numOnes/numElements) of cells are checked
{
cout << "\nÜberspringe Nullen\n";
for (uint i = 0; i < numElements; i++)
{
cout << "\nÜberspringe Nullen\n";
if (!cells[i]->value)
continue;
vector<Cell*> hazardousNeighbors = cells[i]->GetHazards();
@ -133,5 +133,7 @@ int _tmain(int argc, _TCHAR* argv[])
}
}
system("pause");
globalPIC->Dispose();
return 0;
}

View File

@ -68,4 +68,11 @@ PrimImplikant* PrimImplikantCollection::operator[](uint &index){
return this->PIVector.at(index);
return 0;
}
void PrimImplikantCollection::Dispose()
{
for (uint i = 0; i < this->size(); i++)
delete this->at(i);
}

View File

@ -18,17 +18,13 @@ public:
bool valueAt(uint position);
PrimImplikantCollection primImplikantenAt(uint position);
void Dispose();
uint size();
PrimImplikant* back();
PrimImplikant* front();
PrimImplikant* at(uint &index);
PrimImplikant* operator[](uint &index);
~PrimImplikantCollection() // destructor
{
for (uint i = 0; i < this->size(); i++)
delete this->at(i);
}
private:
vector<PrimImplikant*> PIVector;
};