aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-11-28 11:24:47 +0100
committerlonkaars <loek@pipeframe.xyz>2022-11-28 11:24:47 +0100
commit93def2de2991282bac9e320b209657f76cb31177 (patch)
tree4377f7195a949e8718b746648f3b301ad9c63081
parentdeeb409ab2b0e1aeeb5dcdc0f21ed2f2462298e5 (diff)
week 4 klaar?
-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;
+}