diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..70a1f63
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+containers
\ No newline at end of file
diff --git a/.idea/editor.xml b/.idea/editor.xml
index fef3201..8d0e15e 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -245,5 +245,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/hwr2024_b.iml b/.idea/hwr2024_b.iml
index bc2cd87..4c94235 100644
--- a/.idea/hwr2024_b.iml
+++ b/.idea/hwr2024_b.iml
@@ -1,8 +1,2 @@
-
-
-
-
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..f1cca2e
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cpp/.idea/.name b/cpp/.idea/.name
index 5ba3f42..70a1f63 100644
--- a/cpp/.idea/.name
+++ b/cpp/.idea/.name
@@ -1 +1 @@
-pointer
\ No newline at end of file
+containers
\ No newline at end of file
diff --git a/cpp/.idea/misc.xml b/cpp/.idea/misc.xml
index 7a865bb..cb02c5a 100644
--- a/cpp/.idea/misc.xml
+++ b/cpp/.idea/misc.xml
@@ -3,7 +3,7 @@
-
+
\ No newline at end of file
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index 6400fcd..25484a0 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -4,3 +4,4 @@ project(cpp)
add_subdirectory(intro)
add_subdirectory(pointer)
add_subdirectory(classes)
+add_subdirectory(containers)
diff --git a/cpp/classes/CMakeLists.txt b/cpp/classes/CMakeLists.txt
index 4c41146..ebe070b 100644
--- a/cpp/classes/CMakeLists.txt
+++ b/cpp/classes/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 4.1)
-project(pointer)
+project(classes)
set(CMAKE_CXX_STANDARD 20)
-add_executable(pointer main.cpp ClassA.cpp)
+add_executable(classes main.cpp ClassA.cpp)
diff --git a/cpp/classes/ClassA.cpp b/cpp/classes/ClassA.cpp
index 135d247..d51d878 100644
--- a/cpp/classes/ClassA.cpp
+++ b/cpp/classes/ClassA.cpp
@@ -2,6 +2,36 @@
#include
+ClassA::ClassA() : IComparable(), _number(0), _pDecimal(new float(0.0f)) {
+ std::cout << "ClassA()" << std::endl;
+
+ // _pDecimal = new float(0.0f);
+}
+
+ClassA::ClassA(const ClassA &other) :
+ IComparable(),
+ _number(other._number),
+ _pDecimal(new float(*other._pDecimal)) {
+
+ std::cout << "ClassA(const ClassA &other)" << std::endl;
+
+ // // for presentation only
+ // // shallow copy
+ // _number = other._number;
+ // *_pDecimal = *other._pDecimal;
+ //
+ // // deep copy
+ // _number = other._number;
+ // _pDecimal = new float(*other._pDecimal);
+}
+
+ClassA::~ClassA() {
+ std::cout << "~ClassA()" << std::endl;
+
+ delete _pDecimal;
+ _pDecimal = nullptr;
+}
+
void ClassA::Print() {
std::cout << "ClassA" << std::endl;
}
diff --git a/cpp/classes/ClassA.h b/cpp/classes/ClassA.h
index 8d1434a..2e3fe2f 100644
--- a/cpp/classes/ClassA.h
+++ b/cpp/classes/ClassA.h
@@ -8,16 +8,23 @@ class ClassA : public IComparable {
public:
// public
+ ClassA(); // default constructor
+ ClassA(const ClassA& other); // copy constructor
+ ~ClassA() override; // destructor
+
void Print();
int CompareTo(IComparable* other) override;
+ const float& GetDecimal() const { return *_pDecimal; }
+ void SetDecimal(float decimal) { *_pDecimal = decimal; }
+
protected:
// protected
private:
// private
int _number = 0;
+ float* _pDecimal = nullptr;
};
-
#endif //POINTER_CLASSA_H
\ No newline at end of file
diff --git a/cpp/classes/IComparable.h b/cpp/classes/IComparable.h
index 08b9186..3307ed3 100644
--- a/cpp/classes/IComparable.h
+++ b/cpp/classes/IComparable.h
@@ -1,8 +1,13 @@
#ifndef POINTER_ICOMPARABLE_H
#define POINTER_ICOMPARABLE_H
+#include
class IComparable {
public:
+ // only for presentation purposes
+ IComparable() { std::cout << "IComparable()" << std::endl; }
+ virtual ~IComparable() { std::cout << "~IComparable()" << std::endl; }
+
virtual int CompareTo(IComparable* other) = 0;
};
diff --git a/cpp/classes/main.cpp b/cpp/classes/main.cpp
index 29461c1..2be1926 100644
--- a/cpp/classes/main.cpp
+++ b/cpp/classes/main.cpp
@@ -1,4 +1,5 @@
#include "ClassA.h"
+#include
int main() {
ClassA a{};
@@ -20,5 +21,24 @@ int main() {
delete pComparable;
pComparable = nullptr;
+ // copy object
+ ClassA a2 = a;
+
+ std::list list;
+ std::list::iterator it;
+
+ for (it = list.begin(); it != list.end(); ++it) {
+ it->Print();
+ }
+
+ std::list list2;
+ std::list::iterator it2;
+
+ for (it2 = list2.begin(); it2 != list2.end(); ++it2) {
+ (*it2)->CompareTo(&a);
+ }
+
+ IComparable* pComparables[10];
+
return 0;
}
diff --git a/cpp/containers/CMakeLists.txt b/cpp/containers/CMakeLists.txt
new file mode 100644
index 0000000..20cfbd9
--- /dev/null
+++ b/cpp/containers/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 4.1)
+project(containers)
+
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_FLAGS -pedantic-errors)
+
+add_executable(containers main.cpp
+ functions.cpp)
diff --git a/cpp/containers/functions.cpp b/cpp/containers/functions.cpp
new file mode 100644
index 0000000..daf66ec
--- /dev/null
+++ b/cpp/containers/functions.cpp
@@ -0,0 +1,14 @@
+#include
+
+void printArrayAtPosition(int *array, int index) {
+ if (array == nullptr) {
+ return;
+ }
+ if (index < 0) {
+ return;
+ }
+
+ std::cout << "size of array: " << sizeof(array) << std::endl;
+ std::cout << array[index] << std::endl;
+}
+
diff --git a/cpp/containers/functions.h b/cpp/containers/functions.h
new file mode 100644
index 0000000..fdedda8
--- /dev/null
+++ b/cpp/containers/functions.h
@@ -0,0 +1,10 @@
+//
+// Created by David Hackbarth on 20.02.26.
+//
+
+#ifndef CONTAINERS_FUNCTIONS_H
+#define CONTAINERS_FUNCTIONS_H
+
+void printArrayAtPosition(int* array, int index);
+
+#endif //CONTAINERS_FUNCTIONS_H
diff --git a/cpp/containers/main.cpp b/cpp/containers/main.cpp
new file mode 100644
index 0000000..f90e098
--- /dev/null
+++ b/cpp/containers/main.cpp
@@ -0,0 +1,65 @@
+#include
+#include
+#include
+
+#include "functions.h"
+
+typedef std::list FloatList;
+typedef FloatList::iterator FloatListIterator;
+
+int main() {
+ // C array
+ int numbers[5] = {1, 2, 3, 4, 5}; // stack array
+ const int count = 10;
+ // count *= 2;
+ int numbers2[count];
+ numbers2[0] = 10;
+
+ int* numbers3 = new int[count]; // heap array
+ delete[] numbers3;
+ numbers3 = nullptr;
+
+ // numbers[10] = 100;
+
+ std::cout << "size of numbers: " << sizeof(numbers) << std::endl;
+
+ printArrayAtPosition(numbers, 19);
+
+ // vector
+ std::vector v;
+ v.push_back(10);
+ v.push_back(20);
+ v.push_back(30);
+ v.pop_back();
+ v[1] = 100;
+
+ std::cout << "v: " << v.size() << "/" << v.capacity() << std::endl;
+
+ v.push_back(40);
+
+ std::cout << "v: " << v.size() << "/" << v.capacity() << std::endl;
+
+ v.push_back(50);
+
+ std::cout << "v: " << v.size() << "/" << v.capacity() << std::endl;
+
+ v.push_back(60);
+
+ std::cout << "v: " << v.size() << "/" << v.capacity() << std::endl;
+
+ v.reserve(100);
+
+ std::cout << "v: " << v.size() << "/" << v.capacity() << std::endl;
+
+ printArrayAtPosition(v.data(), 1);
+
+ // list
+ std::list l;
+ std::list::iterator it;
+
+ for (it = l.begin(); it != l.end(); ++it) {
+ std::cout << *it << std::endl;
+ }
+
+ return 0;
+}
\ No newline at end of file