commit bd50c5403f07d0e177de382b1d9be39de0f2cfe7 Author: David Hackbarth Date: Fri Feb 13 12:19:53 2026 +0100 Add `.gitignore` and IntelliJ IDEA project configuration files and projects for cpp intro, pointers and classes diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2262d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,69 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Linker files +*.ilk + +# Debugger Files +*.pdb + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll +*.so.* + + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# Build directories +build/ +Build/ +build-*/ + +# CMake generated files +CMakeFiles/ +CMakeCache.txt +cmake_install.cmake +Makefile +install_manifest.txt +compile_commands.json + +# Temporary files +*.tmp +*.log +*.bak +*.swp + +# vcpkg +vcpkg_installed/ + +# debug information files +*.dwo + +# test output & cache +Testing/ +.cache/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/cpp.iml b/.idea/cpp.iml new file mode 100644 index 0000000..bc2cd87 --- /dev/null +++ b/.idea/cpp.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/editor.xml b/.idea/editor.xml new file mode 100644 index 0000000..ca29dcc --- /dev/null +++ b/.idea/editor.xml @@ -0,0 +1,101 @@ + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e009e75 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/cpp/.idea/.gitignore b/cpp/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/cpp/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/cpp/.idea/.name b/cpp/.idea/.name new file mode 100644 index 0000000..d366d2e --- /dev/null +++ b/cpp/.idea/.name @@ -0,0 +1 @@ +classes \ No newline at end of file diff --git a/cpp/.idea/cpp.iml b/cpp/.idea/cpp.iml new file mode 100644 index 0000000..4c94235 --- /dev/null +++ b/cpp/.idea/cpp.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/cpp/.idea/editor.xml b/cpp/.idea/editor.xml new file mode 100644 index 0000000..8d0e15e --- /dev/null +++ b/cpp/.idea/editor.xml @@ -0,0 +1,345 @@ + + + + + \ No newline at end of file diff --git a/cpp/.idea/encodings.xml b/cpp/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/cpp/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/cpp/.idea/misc.xml b/cpp/.idea/misc.xml new file mode 100644 index 0000000..7a865bb --- /dev/null +++ b/cpp/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/cpp/.idea/modules.xml b/cpp/.idea/modules.xml new file mode 100644 index 0000000..e009e75 --- /dev/null +++ b/cpp/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/cpp/.idea/vcs.xml b/cpp/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/cpp/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt new file mode 100644 index 0000000..6400fcd --- /dev/null +++ b/cpp/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 4.1) +project(cpp) + +add_subdirectory(intro) +add_subdirectory(pointer) +add_subdirectory(classes) diff --git a/cpp/classes/CMakeLists.txt b/cpp/classes/CMakeLists.txt new file mode 100644 index 0000000..6b97e80 --- /dev/null +++ b/cpp/classes/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 4.1) +project(classes) + +set(CMAKE_CXX_STANDARD 20) + +add_executable(classes + main.cpp + ClassA.cpp +) diff --git a/cpp/classes/ClassA.cpp b/cpp/classes/ClassA.cpp new file mode 100644 index 0000000..1a156d4 --- /dev/null +++ b/cpp/classes/ClassA.cpp @@ -0,0 +1,12 @@ +#include "ClassA.h" + +#include + +void ClassA::Print() +{ + std::cout << "ClassA" << std::endl; +} + +int ClassA::CompareTo(IComparable *other) { + return 0; +} diff --git a/cpp/classes/ClassA.h b/cpp/classes/ClassA.h new file mode 100644 index 0000000..f80ce9b --- /dev/null +++ b/cpp/classes/ClassA.h @@ -0,0 +1,23 @@ +#ifndef CLASSES_CLASSA_H +#define CLASSES_CLASSA_H +#include "IComparable.h" + + +class ClassA : public IComparable { +// private + +public: + // public + void Print(); + int CompareTo(IComparable* other) override; + +protected: + // protected + +private: + // private + int _number = 0; +}; + + +#endif //CLASSES_CLASSA_H \ No newline at end of file diff --git a/cpp/classes/IComparable.h b/cpp/classes/IComparable.h new file mode 100644 index 0000000..904dd2f --- /dev/null +++ b/cpp/classes/IComparable.h @@ -0,0 +1,9 @@ +#ifndef CLASSES_ICOMPARABLE_H +#define CLASSES_ICOMPARABLE_H + +class IComparable { +public: + virtual int CompareTo(IComparable* other) = 0; +}; + +#endif //CLASSES_ICOMPARABLE_H \ No newline at end of file diff --git a/cpp/classes/main.cpp b/cpp/classes/main.cpp new file mode 100644 index 0000000..8033109 --- /dev/null +++ b/cpp/classes/main.cpp @@ -0,0 +1,17 @@ +#include "ClassA.h" + +int main() { + ClassA a; + a.Print(); + + ClassA* pA = nullptr; + pA = new ClassA(); + pA->Print(); + // (*pA).Print(); // same as above, but more complex to write + delete pA; + pA = nullptr; + + a.CompareTo(pA); + + return 0; +} \ No newline at end of file diff --git a/cpp/intro/.idea/.gitignore b/cpp/intro/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/cpp/intro/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/cpp/intro/.idea/cpp.iml b/cpp/intro/.idea/cpp.iml new file mode 100644 index 0000000..4c94235 --- /dev/null +++ b/cpp/intro/.idea/cpp.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/cpp/intro/.idea/editor.xml b/cpp/intro/.idea/editor.xml new file mode 100644 index 0000000..8d0e15e --- /dev/null +++ b/cpp/intro/.idea/editor.xml @@ -0,0 +1,345 @@ + + + + + \ No newline at end of file diff --git a/cpp/intro/.idea/encodings.xml b/cpp/intro/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/cpp/intro/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/cpp/intro/.idea/misc.xml b/cpp/intro/.idea/misc.xml new file mode 100644 index 0000000..0b76fe5 --- /dev/null +++ b/cpp/intro/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/cpp/intro/.idea/modules.xml b/cpp/intro/.idea/modules.xml new file mode 100644 index 0000000..e009e75 --- /dev/null +++ b/cpp/intro/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/cpp/intro/.idea/vcs.xml b/cpp/intro/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/cpp/intro/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/cpp/intro/CMakeLists.txt b/cpp/intro/CMakeLists.txt new file mode 100644 index 0000000..a9c9840 --- /dev/null +++ b/cpp/intro/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 4.1) +project(intro) + +set(CMAKE_CXX_STANDARD 20) + +add_executable(intro main.cpp + functions.cpp) diff --git a/cpp/intro/functions.cpp b/cpp/intro/functions.cpp new file mode 100644 index 0000000..519437d --- /dev/null +++ b/cpp/intro/functions.cpp @@ -0,0 +1,7 @@ +// +// Created by David Hackbarth on 06.02.26. +// + +#include "functions.h" + +void functionE() {} \ No newline at end of file diff --git a/cpp/intro/functions.h b/cpp/intro/functions.h new file mode 100644 index 0000000..10ed8d4 --- /dev/null +++ b/cpp/intro/functions.h @@ -0,0 +1,12 @@ +#pragma once +// +// Created by David Hackbarth on 06.02.26. +// + +#ifndef CPP_FUNCTIONS_H +#define CPP_FUNCTIONS_H + +void functionE(); +// void functionF() {} + +#endif //CPP_FUNCTIONS_H \ No newline at end of file diff --git a/cpp/intro/main.cpp b/cpp/intro/main.cpp new file mode 100644 index 0000000..bf8695b --- /dev/null +++ b/cpp/intro/main.cpp @@ -0,0 +1,36 @@ +#include +#include "functions.h" + +using namespace std; + +void functionB() {} +void functionC(); // forward declaration +void functionD(); // forward declaration + +int main() { + std::cout << "Hello, World!" << std::endl; + + // functionA(); // compiler error - functionA is defined after call + functionB(); // no error - functionB is defined before call + // functionC(); // linker error - functionC is declared but not defined + functionD(); // no error - functionD is declared and defined + functionE(); + // functionF(); // linker error - functionF is defined twice + + byte b; + int8_t b2; + short s; + int i; + long l; + long long ll; + + cout << "size of short: " << sizeof(short) << endl; + cout << "size of int: " << sizeof(int) << endl; + cout << "size of long: " << sizeof(long) << endl; + cout << "size of long long: " << sizeof(long long) << endl; + + return 0; +} + +void functionA() {} +void functionD() {} diff --git a/cpp/pointer/CMakeLists.txt b/cpp/pointer/CMakeLists.txt new file mode 100644 index 0000000..42054c8 --- /dev/null +++ b/cpp/pointer/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 4.1) +project(pointer) + +set(CMAKE_CXX_STANDARD 20) + +add_executable(pointer main.cpp) diff --git a/cpp/pointer/main.cpp b/cpp/pointer/main.cpp new file mode 100644 index 0000000..b8a87cf --- /dev/null +++ b/cpp/pointer/main.cpp @@ -0,0 +1,109 @@ +#include +#include + +void changeInt(int n); +void changeIntPointer(int* pN); +void changeIntReference(int& n); + +void createInt(int* pI); +void createInt(int** ppI); + +int main() +{ + int i = 1; + int* pI = nullptr; + pI = &i; + *pI = 10; + std::cout << "i = " << i << std::endl; + pI = new int; + pI = new int(); // CAUTION - created a memory leak + pI = new int(10); // CAUTION - created a memory leak + delete pI; + pI = nullptr; + + changeInt(i); + changeIntPointer(&i); + changeIntReference(i); + + // const + // const int ci = 10; // integer is constant + // const int* pCi = new int(0); // pointer to a constant integer + // pCi = new int(0); + // *pCi = 0; + // int const * pic = new int(0); // pointer to a constant integer + // pic = new int(0); + // *pic = 0; + // const int const * pcic = new int(0); // pointer to a constant integer + // pcic = new int(0); + // *pcic = 0; + // int * const cpi = new int(0); // constant pointer to an integer + // cpi = new int(0); + // *cpi = 0; + // int const * const cpic = new int(0); // constant pointer to a constant integer + // cpic = new int(0); + // *cpic = 0; + // const int * const cpci = new int(0); // constant pointer to a constant integer + // cpci = new int(0); + // *cpci = 0; + // const int const * const cpcic = new int(0); // constant pointer to a constant integer + // cpcic = new int(0); + // *cpcic = 0; + + createInt(pI); + createInt(&pI); + + if (pI != nullptr) { + delete pI; + pI = nullptr; + } + + std::unique_ptr upI = std::make_unique(0); + // std::unique_ptr upI2 = upI; // don't work + std::unique_ptr upI2 = std::make_unique(*upI); + + std::shared_ptr spI = std::make_shared(0); + std::shared_ptr spI2 = spI; + spI.reset(); + + std::weak_ptr wpI = spI2; + if (wpI.expired()) { + std::cout << "wpI is expired" << std::endl; + } + else { + std::cout << "wpI is not expired" << std::endl; + std::shared_ptr spI3 = wpI.lock(); + } + + spI2.reset(); + + if (wpI.expired()) { + std::cout << "wpI is expired" << std::endl; + } + else { + std::cout << "wpI is not expired" << std::endl; + } + + return 0; +} + +void changeInt(int n) { + n *= 2; +} + +void changeIntPointer(int* pN) { + if (pN == nullptr) return; + *pN *= 2; +} + +void changeIntReference(int& n) { + n *= 2; +} + +void createInt(int* pI) { + pI = new int(0); +} + +void createInt(int** ppI) { + if (ppI == nullptr) return; + *ppI = new int(0); +}