aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--oop2w4/MijnKlasse.cpp20
-rw-r--r--oop2w4/MijnKlasse.h13
-rw-r--r--oop2w4/main.cpp15
3 files changed, 48 insertions, 0 deletions
diff --git a/oop2w4/MijnKlasse.cpp b/oop2w4/MijnKlasse.cpp
new file mode 100644
index 0000000..55f8af6
--- /dev/null
+++ b/oop2w4/MijnKlasse.cpp
@@ -0,0 +1,20 @@
+#include <iostream>
+
+#include "MijnKlasse.h"
+
+MijnKlasse::MijnKlasse(int n) {
+ _n = n;
+ _thread = new std::thread(this->showNum, this->_n);
+}
+
+MijnKlasse::~MijnKlasse() {
+ if (_thread != nullptr) {
+ _thread->join();
+ delete _thread;
+ _thread = nullptr;
+ }
+}
+
+void MijnKlasse::showNum(int n) {
+ std::cout << std::endl << n << " from thread " << std::this_thread::get_id();
+}
diff --git a/oop2w4/MijnKlasse.h b/oop2w4/MijnKlasse.h
new file mode 100644
index 0000000..f8b74de
--- /dev/null
+++ b/oop2w4/MijnKlasse.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <thread>
+
+class MijnKlasse {
+ private:
+ std::thread* _thread = nullptr;
+ int _n = 0;
+ public:
+ MijnKlasse(int n);
+ ~MijnKlasse();
+ static void showNum(int n);
+};
diff --git a/oop2w4/main.cpp b/oop2w4/main.cpp
index e69de29..ad3f2cd 100644
--- a/oop2w4/main.cpp
+++ b/oop2w4/main.cpp
@@ -0,0 +1,15 @@
+#include <thread>
+#include <iostream>
+
+#include "MijnKlasse.h"
+
+int main() {
+ MijnKlasse* instanties[100];
+
+ for (int n = 0; n < 100; n++)
+ instanties[n] = new MijnKlasse(n);
+ for (int n = 0; n < 100; n++)
+ delete instanties[n];
+
+ std::cout << std::endl << "Ready" << std::endl;
+}