From 3bf1e178a811cde0f092215f883ad7431f519207 Mon Sep 17 00:00:00 2001 From: Jonny007-MKD <1-23-4-5@web.de> Date: Thu, 21 Nov 2013 21:05:03 +0100 Subject: [PATCH] Changed destructor to Dispose() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Hazard/Hazard/Hazard.cpp | 8 +++++--- Hazard/Hazard/PrimImplikantCollection.cpp | 7 +++++++ Hazard/Hazard/PrimImplikantCollection.h | 8 ++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Hazard/Hazard/Hazard.cpp b/Hazard/Hazard/Hazard.cpp index 69af299..5d84d3d 100644 --- a/Hazard/Hazard/Hazard.cpp +++ b/Hazard/Hazard/Hazard.cpp @@ -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 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 hazardousNeighbors = cells[i]->GetHazards(); @@ -133,5 +133,7 @@ int _tmain(int argc, _TCHAR* argv[]) } } system("pause"); + + globalPIC->Dispose(); return 0; } \ No newline at end of file diff --git a/Hazard/Hazard/PrimImplikantCollection.cpp b/Hazard/Hazard/PrimImplikantCollection.cpp index c1d3e4d..911c607 100644 --- a/Hazard/Hazard/PrimImplikantCollection.cpp +++ b/Hazard/Hazard/PrimImplikantCollection.cpp @@ -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); } \ No newline at end of file diff --git a/Hazard/Hazard/PrimImplikantCollection.h b/Hazard/Hazard/PrimImplikantCollection.h index b1f9733..77a5dd4 100644 --- a/Hazard/Hazard/PrimImplikantCollection.h +++ b/Hazard/Hazard/PrimImplikantCollection.h @@ -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 PIVector; };