├── .vscode ├── c_cpp_properties.json ├── launch.json ├── settings.json └── tasks.json ├── 01.Array-ArrayPointer-Vector-List ├── ListDefinition.cpp ├── ListDefinition.h ├── VectorClassEx.cpp ├── VectorClassEx.h ├── VectorDefinition.cpp ├── VectorDefinition.exe ├── VectorDefinition.h ├── main.cpp └── main.exe ├── 02.ctorinit-macros-casting ├── main.cpp ├── main.exe └── main.h ├── 03.Flow-Control ├── Flow_Control.cpp ├── Flow_Control.h ├── main.cpp └── main.exe ├── 04.Interface-Final-Overriding-Friend-Ambiguisebaseclass ├── UAVBase.h ├── UAVBody.cpp ├── UAVBody.h ├── UAVBodyElectronicSystems.cpp ├── UAVBodyElectronicSystems.h ├── UAVWings.h └── main.exe ├── 05.Metaprogramming ├── Meta.h ├── main.cpp └── main.exe ├── 06.MultiThreading ├── Multithread.cpp ├── Multithread.exe ├── Multithread.h ├── ThreadingExample │ ├── ThreadBaseClass.cpp │ ├── ThreadBaseClass.exe │ ├── ThreadBaseClass.h │ ├── UavBaykarContrDerived.cpp │ ├── UavBaykarContrDerived.h │ ├── UavTaiContrDerived.cpp │ ├── UavTaiContrDerived.h │ ├── main.cpp │ └── main.exe ├── main.cpp └── main.exe ├── 07.mutable-friend-type-linkedList ├── LinkedList │ ├── List.cpp │ ├── List.h │ ├── ListNode.cpp │ └── ListNode.h ├── Type │ ├── BasicTypeKeyword.cpp │ ├── BasicTypeKeyword.h │ ├── VariableDeclerationKeyword.cpp │ ├── VariableDeclerationKeyword.h │ ├── typekeyword.cpp │ └── typekeyword.h ├── friend.cpp ├── friend.h ├── friendcall.cpp ├── friendcall.h ├── main.cpp ├── main.exe ├── mutable.cpp └── mutable.h ├── 08.Overload-NestedClass-Explicit ├── Overload-NestedClass-Explicit.cpp ├── Overload-NestedClass-Explicit.exe ├── Overload-NestedClass-Explicit.h ├── main.cpp └── main.exe ├── 09.PassBy-Mutable-Inline ├── PassBy-Mutable-Inline.cpp ├── PassBy-Mutable-Inline.h ├── main.cpp └── main.exe ├── 10.Pointer_example-Singleton ├── main.cpp ├── main.exe ├── pointerclass.cpp └── pointerclass.h ├── 11.ReturnSeveralValues ├── ReturnMultiVal.cpp ├── ReturnMultiVal.h ├── main.cpp └── main.exe ├── 12.RuleOfFive-RuleofThree ├── RuleofFive-Ruleofthree.cpp ├── RuleofFive-Ruleofthree.h ├── main.cpp └── main.exe ├── 13.Smartptr-Lambda-Movesemantics-const ├── ConstExamples.cpp ├── ConstExamples.h ├── MoveSemantics-Struct-CopyCostruct.cpp ├── MoveSemantics-Struct-CopyCostruct.h ├── SmartPointers-Lambda.cpp ├── SmartPointers-Lambda.h ├── main.cpp └── main.exe ├── 14.Static_example ├── main.cpp ├── main.exe └── main.h ├── 15.Template-Example ├── Untitled1.cpp ├── Untitled1.exe ├── Untitled1.h └── vc140.pdb ├── 16.Pointers ├── PointerBasics │ ├── PointerBasics.cpp │ └── PointerBasics.h ├── main.cpp └── main.exe ├── 17.ClassAndStructure ├── AccessSpecifier │ ├── AccessSpecifier.cpp │ ├── AccessSpecifier.exe │ └── AccessSpecifier.h ├── ClassBasics │ ├── ClassBasics.cpp │ └── ClassBasics.h ├── FinalClassAndStructs │ ├── FinalClassAndStructs.cpp │ └── FinalClassAndStructs.h ├── main.cpp └── main.exe ├── 18.Overloading ├── CV-Qualifier-Overloading │ ├── CvQualifierOverloading.cpp │ └── CvQualifierOverloading.h ├── FunctionOverloading │ ├── FunctionOverloading.cpp │ └── FunctionOverloading.h ├── main.cpp └── main.exe ├── 19.MemberFunctions ├── InlineFunctions │ ├── InlineFunctions.cpp │ └── InlineFunctions.h ├── VirtualMemberFunctions │ ├── FinalVirtualFunctionsBase.cpp │ ├── FinalVirtualFunctionsBase.h │ ├── FinalVirtualFunctionsDerived.cpp │ └── FinalVirtualFunctionsDerived.h ├── main.cpp └── main.exe ├── 20.Namespaces ├── WhatisNameSpace │ ├── NameSpaceExample.h │ └── NamespaceExample.cpp ├── main.cpp └── main.exe ├── 21.STD-ARRAY ├── StdArray.cpp ├── StdArray.h ├── main.cpp └── main.exe ├── 22.STD-MAP ├── StdMap.cpp ├── StdMap.exe ├── StdMap.h ├── main.cpp └── main.exe ├── 23.STD-UNORDERED_MAP ├── UnorderedMap.cpp ├── UnorderedMap.exe ├── UnorderedMap.h ├── main.cpp └── main.exe ├── 24.STRUCTS ├── StructBasePackages.h ├── StructExample.cpp ├── StructExample.exe ├── StructExample.h └── main.cpp ├── 25.STD-FUNCTION ├── StdFunction.cpp ├── StdFunction.exe ├── StdFunction.h ├── main.cpp └── main.exe ├── 26.STD-FORWARD_LIST-PAIR ├── StdForwardList.cpp ├── StdForwardList.exe ├── StdForwardList.h ├── main.cpp └── main.exe ├── 27.STD-OPTIONAL ├── StdOptional.cpp ├── StdOptional.exe ├── StdOptional.h ├── main.cpp └── main.exe ├── 28.STD-VARIANT-ANY-SET-MULTISET ├── StdVariantAny.cpp ├── StdVariantAny.h ├── main.cpp └── main.exe ├── 29.ENUMS ├── EnumExample.cpp ├── EnumExample.h ├── main.cpp └── main.exe ├── 30.IntegerSequence ├── IntegerSequence.cpp ├── IntegerSequence.h └── main.cpp ├── 31.Inline Varibales ├── InlineVariables.cpp ├── InlineVariables.h ├── main.cpp └── main.exe ├── 32.Chrono(Time Measurement) ├── TimeMeasurement.cpp ├── TimeMeasurement.h ├── main.cpp └── main.exe ├── 33.Exceptions-TryCatch ├── Exceptions.cpp ├── Exceptions.exe ├── Exceptions.h ├── main.cpp └── main.exe ├── 34.LAMBDAS ├── Lambdas.cpp ├── Lambdas.exe ├── Lambdas.h ├── main.cpp └── main.exe ├── 35.ValueCategories ├── ValueCategories.cpp ├── ValueCategories.exe ├── ValueCategories.h ├── main.cpp └── main.exe ├── 36.Preprocessors ├── ConditionalLogic.cpp ├── ConditionalLogic.h ├── IncludeGuards.cpp ├── IncludeGuards.h ├── Macros.cpp ├── Macros.h ├── UsefulMacros.h ├── main.cpp └── main.exe ├── 37.Templates ├── Templates.cpp ├── Templates.exe ├── Templates.h ├── TemplatesAnother.cpp ├── TemplatesAnother.exe ├── main.cpp └── main.exe ├── 38.ExplicitTypeConversion(CASTING) ├── Casting.cpp ├── Casting.h └── main.cpp ├── 39.TypeInference-Auto ├── TypeInference.cpp ├── TypeInference.exe ├── TypeInference.h ├── main.cpp └── main.exe ├── 40.TypeTraits ├── TypeTraits.cpp ├── TypeTraits.exe ├── TypeTraits.h ├── main.cpp └── main.exe ├── 41.TypedefAndAlias ├── TypedefAndAlias.cpp ├── TypedefAndAlias.h ├── main.cpp └── main.exe ├── 42.TypeDeduction ├── TypeDeduction.cpp ├── TypeDeduction.h ├── main.cpp └── main.exe ├── 43-Alignment ├── Alignment.cpp ├── Alignment.exe ├── Alignment.h ├── main.cpp └── main.exe ├── 44-UndefinedBehaviour ├── UndefinedBehaviour.cpp ├── UndefinedBehaviour.h ├── main.cpp └── main.exe ├── 45-CopyEllision ├── CopyEllision.cpp ├── CopyEllision.h ├── main.cpp └── main.exe ├── 46-OverloadResolution ├── OverloadResolution.cpp ├── OverloadResolution.h ├── main.cpp └── main.exe ├── 47-ConstExpr ├── ConstExpr.cpp ├── ConstExpr.h ├── main.cpp └── main.exe ├── 48-MemoryManagement ├── MemoryManagement.cpp ├── MemoryManagement.exe ├── MemoryManagement.h ├── main.cpp └── main.exe ├── 49-StaticAssert copy ├── StaticAssert.cpp ├── StaticAssert.h ├── main.cpp └── main.exe ├── 50-CallableObjects ├── CallableObjects.cpp ├── CallableObjects.exe ├── CallableObjects.h ├── main.cpp └── main.exe ├── 51-BitManipulators ├── BitManipulators.cpp ├── BitManipulators.exe ├── BitManipulators.h ├── main.cpp └── main.exe ├── 52-JSON_File ├── JsonFileReader.cpp ├── JsonFileReader.h ├── JsonFileWriter.cpp ├── JsonFileWriter.exe ├── JsonFileWriter.h ├── main.cpp ├── main.exe ├── test1.json └── test2.json ├── 53-Algorithm ├── Algorithm-Examples │ ├── ArrayExamples.cpp │ ├── ArrayExamples.exe │ ├── ArrayExamples.h │ ├── main.cpp │ └── main.exe ├── ComparisonAlgorithm.cpp ├── ComparisonAlgorithm.h ├── CountingAlgorithm.cpp ├── CountingAlgorithm.h ├── ModifyingSequenceAlgorithm.cpp ├── ModifyingSequenceAlgorithm.h ├── SearchAlgorithms.cpp ├── SearchAlgorithms.h ├── SetAndOperationalAlgorithms.cpp ├── SetAndOperationalAlgorithms.h ├── SortingAlgorithms.cpp ├── SortingAlgorithms.h ├── SwapAndExchangeAlgorithms.cpp ├── SwapAndExchangeAlgorithms.h ├── main.cpp └── main.exe ├── 54-XML_File ├── Test.xml ├── XmlController.cpp ├── XmlController.h ├── main.cpp ├── main.exe ├── tinyxml2.cpp ├── tinyxml2.h └── xmltest.cpp ├── 55-FunctionPointers ├── FunctionPointers.cpp ├── FunctionPointers.exe ├── FunctionPointers.h ├── main.cpp └── main.exe ├── 56-Database ├── DatabaseController.cpp ├── DatabaseController.h ├── Test.db ├── Test.sqbpro ├── main.cpp └── main.exe ├── 57-Stream ├── BinaryData.bin ├── Data.txt ├── DataOstream.txt ├── StreamController.cpp ├── StreamController.exe ├── StreamController.h ├── main.cpp └── main.exe ├── 58-StringOperations ├── StringOperations.cpp ├── StringOperations.h ├── main.cpp └── main.exe ├── 59-File_IO_Operations └── 1-cstdio │ ├── CStdioOperations.cpp │ ├── CStdioOperations.h │ ├── NewExampleFile.txt │ ├── main.cpp │ └── main.exe ├── 60-EventBaseExample ├── EventClasses.h ├── EventClassesInterface.h ├── EventDispatcher.exe ├── EventDispatcher.h ├── EventListeners.h ├── EventListenersInterface.h ├── EventTypes.h ├── main.cpp └── main.exe └── README.md /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Win32", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "defines": [ 9 | "_DEBUG", 10 | "UNICODE", 11 | "_UNICODE" 12 | ], 13 | "windowsSdkVersion": "10.0.18362.0", 14 | "compilerPath": "C:/msys64/mingw64/bin/g++.exe", 15 | "cStandard": "c11", 16 | "cppStandard": "c++20", 17 | "intelliSenseMode": "windows-gcc-x86" 18 | } 19 | ], 20 | "version": 4 21 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "name": "g++.exe - Build and debug active file", 10 | "type": "cppdbg", 11 | "request": "launch", 12 | "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", 13 | "args": [], 14 | "stopAtEntry": false, 15 | "cwd": "${workspaceFolder}", 16 | "environment": [], 17 | "externalConsole": false, 18 | "MIMode": "gdb", 19 | "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe", 20 | "setupCommands": [ 21 | { 22 | "description": "Enable pretty-printing for gdb", 23 | "text": "-enable-pretty-printing", 24 | "ignoreFailures": true 25 | } 26 | ], 27 | "preLaunchTask": "g++.exe build active file" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "shell", 5 | "label": "g++.exe build active file", 6 | "command": "C:\\msys64\\mingw64\\bin\\g++.exe", 7 | "args": [ 8 | "-g", 9 | "${fileDirname}\\**.cpp", 10 | //"${fileDirname}\\**.h", 11 | "-ljsoncpp", 12 | "-lsqlite3", 13 | "-o", 14 | "${fileDirname}\\${fileBasenameNoExtension}.exe", 15 | "-std=c++2a" 16 | ], 17 | "options": { 18 | "cwd": "${workspaceFolder}"//"C:\\MinGW\\bin" //"C:\\Qt\\Tools\\mingw730_64\\bin" 19 | }, 20 | "problemMatcher": ["$gcc"], 21 | "group": { 22 | "kind": "build", 23 | "isDefault": true 24 | } 25 | }, 26 | { 27 | "type": "cppbuild", 28 | "label": "C/C++: cl.exe build active file", 29 | "command": "cl.exe", 30 | "args": [ 31 | "/Zi", 32 | "/EHsc", 33 | "/nologo", 34 | "/Fe:", 35 | "${fileDirname}\\${fileBasenameNoExtension}.exe", 36 | "${file}" 37 | ], 38 | "options": { 39 | "cwd": "${workspaceFolder}" 40 | }, 41 | "problemMatcher": [ 42 | "$msCompile" 43 | ], 44 | "group": { 45 | "kind": "build", 46 | "isDefault": true 47 | }, 48 | "detail": "compiler: g++.exe" 49 | } 50 | ], 51 | "version": "2.0.0" 52 | } -------------------------------------------------------------------------------- /01.Array-ArrayPointer-Vector-List/VectorClassEx.cpp: -------------------------------------------------------------------------------- 1 | #include "VectorClassEx.h" 2 | 3 | VectorClassEx::VectorClassEx() : 4 | intDef(0), 5 | stringDef("0") 6 | { 7 | } 8 | 9 | int VectorClassEx::getIntDef() const { 10 | return intDef; 11 | } 12 | 13 | void VectorClassEx::setIntDef(const int pIntDef) { 14 | intDef = pIntDef; 15 | } 16 | 17 | std::string VectorClassEx::getStringDef() const{ 18 | return stringDef; 19 | } 20 | 21 | void VectorClassEx::setStringDef(const std::string pStringDef){ 22 | stringDef = pStringDef; 23 | } -------------------------------------------------------------------------------- /01.Array-ArrayPointer-Vector-List/VectorClassEx.h: -------------------------------------------------------------------------------- 1 | #ifndef VECTORCLASSEX_H 2 | #define VECTORCLASSEX_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /* A function defined with the inline specifier is an inline function. An inline function can be multiply defined without 10 | violating the One Definition Rule, and can therefore be defined in a header with external linkage. Declaring a 11 | function inline hints to the compiler that the function should be inlined during code generation, but does not 12 | provide a guarantee. */ 13 | class VectorClassEx 14 | { 15 | public: 16 | VectorClassEx(); 17 | VectorClassEx(int val) = delete; 18 | VectorClassEx(VectorClassEx &&ruleOfFive) noexcept = default; //III. MOVE CONSTRUCTOR 19 | VectorClassEx(const VectorClassEx &ruleOfThree) = default; // II. COPY CONSTRUCTOR 20 | VectorClassEx &operator=(const VectorClassEx &ruleOfThree) = delete; // III. COPY ASSIGNMENT 21 | ~VectorClassEx() = default; 22 | 23 | int getIntDef() const; 24 | void setIntDef(const int pIntDef); 25 | 26 | std::string getStringDef() const; 27 | void setStringDef(const std::string pStringDef); 28 | 29 | private: 30 | int intDef; 31 | std::string stringDef; 32 | 33 | 34 | }; 35 | 36 | #endif -------------------------------------------------------------------------------- /01.Array-ArrayPointer-Vector-List/VectorDefinition.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/01.Array-ArrayPointer-Vector-List/VectorDefinition.exe -------------------------------------------------------------------------------- /01.Array-ArrayPointer-Vector-List/main.cpp: -------------------------------------------------------------------------------- 1 | #include "VectorDefinition.h" 2 | #include "Listdefinition.h" 3 | //#include 4 | 5 | int main(){ 6 | VectorDefinition vectorDefinition; 7 | ListDefinition listDefinition; 8 | 9 | //vectorDefinition.vectorInitializations(); 10 | //vectorDefinition.vectorAllOperations(); 11 | //vectorDefinition.vectorStructArray(); 12 | //vectorDefinition.vectorTransferOpStruct(); 13 | //vectorDefinition.vectorIteratorOp(); 14 | //vectorDefinition.vectorDynamicAllocation(); 15 | 16 | //vectorDefinition.vectorInitializations(); 17 | //vectorDefinition.vectorAllOperations(); 18 | //vectorDefinition.vectorStructArray(); 19 | //vectorDefinition.vectorClassAproach(); 20 | //vectorDefinition.correctWayOfVector(); 21 | //vectorDefinition.copyOpOfTheVector(); 22 | 23 | vectorDefinition.correctwayOfVectorWithShrink(); 24 | vectorDefinition.correctwayOfVectorWithShrink(); 25 | vectorDefinition.correctwayOfVectorWithShrink(); 26 | 27 | //listDefinition.listTransferOpStruct(); 28 | //listdefinition.listIteratorOp(); 29 | //listdefinition.listDynamicAllocation(); 30 | 31 | 32 | 33 | } -------------------------------------------------------------------------------- /01.Array-ArrayPointer-Vector-List/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/01.Array-ArrayPointer-Vector-List/main.exe -------------------------------------------------------------------------------- /02.ctorinit-macros-casting/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | Example::Example() : something(true) //THIS IS CTOR INITIALIZATON 3 | { 4 | doubleval = 50.0; 5 | integerval = 30; 6 | } 7 | 8 | Example::~Example() 9 | { 10 | } 11 | 12 | void Example::setVariable(int *pvariable) 13 | { 14 | mVariable = pvariable; 15 | } 16 | 17 | int Example::getVariable() const 18 | { 19 | 20 | return *mVariable; 21 | } 22 | 23 | int main() 24 | { 25 | Example example; 26 | int defvariable = 50; 27 | 28 | std::cout << example.something << " " << HEIGHT << std::endl; 29 | std::cout << static_cast(example.doubleval)<<" and " << static_cast(example.integerval) << std::endl; //STATİC CAST EXAMPLE 30 | 31 | printString("Macro is succesfully defin"); //MACRO DEFINITION FOR PRINTING 32 | 33 | example.setVariable(&defvariable); //GET SET EXAMPLE 34 | std::cout << example.getVariable(); 35 | } -------------------------------------------------------------------------------- /02.ctorinit-macros-casting/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/02.ctorinit-macros-casting/main.exe -------------------------------------------------------------------------------- /02.ctorinit-macros-casting/main.h: -------------------------------------------------------------------------------- 1 | //TEHESE ARE ALL MACROS 2 | #ifndef MAIN_H 3 | #define MAIN_H 4 | 5 | //Macro Definitions 6 | #define WIDTH 1920 7 | 8 | #ifndef HEIGHT 9 | #define HEIGHT 1080 10 | #endif 11 | 12 | /* 13 | #ifdef HEIGHT 14 | #define DEFINED 1 15 | #endif */ 16 | 17 | 18 | #if DEFINED 19 | #define RECT 50 20 | #endif 21 | 22 | #define printString(a) std::cout< 26 | 27 | class Example{ 28 | 29 | public: 30 | Example(); 31 | ~Example(); 32 | 33 | bool something; 34 | double doubleval; 35 | int integerval; 36 | 37 | int getVariable() const; 38 | void setVariable( int *pvariable); 39 | 40 | private: 41 | int *mVariable; 42 | 43 | }; 44 | #endif -------------------------------------------------------------------------------- /03.Flow-Control/Flow_Control.h: -------------------------------------------------------------------------------- 1 | #ifndef FLOW_CONTROL_H 2 | #define FLOW_CONTROL_H 3 | #include 4 | #include 5 | //Author : Burak Dogancay 6 | class Flow_Control{ 7 | 8 | public: 9 | Flow_Control(); 10 | ~Flow_Control(); 11 | 12 | void flowControlSwitch(); 13 | void flowControlTryCatch(); 14 | void flowControlGoto(); 15 | void flowControlForLoop(); 16 | 17 | int getRet_Def(); 18 | void setRet_Def(int pRet_Def); 19 | 20 | private: 21 | enum class SwitchControl{ 22 | First, 23 | Second, 24 | Third, 25 | Forth 26 | }; 27 | int mRet_Def; 28 | int mGoto_Def; 29 | SwitchControl mswitchcnt; 30 | 31 | }; 32 | 33 | #endif -------------------------------------------------------------------------------- /03.Flow-Control/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Flow_Control.h" 2 | int main(){ 3 | Flow_Control flowcontrol; 4 | //flowcontrol.flowControlSwitch(); 5 | //flowcontrol.flowControlTryCatch(); 6 | flowcontrol.flowControlForLoop(); 7 | //flowcontrol.flowControlGoto(); 8 | } -------------------------------------------------------------------------------- /03.Flow-Control/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/03.Flow-Control/main.exe -------------------------------------------------------------------------------- /04.Interface-Final-Overriding-Friend-Ambiguisebaseclass/UAVBase.h: -------------------------------------------------------------------------------- 1 | #ifndef UAVBASE_H 2 | #define UAVBASE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | //Author : Burak Dogancay 10 | //INTERFACE ALL METHODS ARE VIRTUAL,ABSTRACTCLASS 11 | //INHERITANCE 12 | //Principal of abstarction , you should make all data members private and provide getter and setter methods 13 | class UAVBase 14 | { 15 | public: 16 | 17 | virtual ~UAVBase(){}//Always make your destructor virtual.Making base class destructor virtual guarantees that the object of derived class is destructed properly 18 | 19 | //virtual void missionGeneration() final ; //preventing overriding method 20 | virtual void flyOperations() = 0; // or use "= default" 21 | virtual void malfunctionShow() = 0; 22 | 23 | }; 24 | static_assert(sizeof(UAVBase) > 1, "No pointer to vtable"); 25 | 26 | #endif -------------------------------------------------------------------------------- /04.Interface-Final-Overriding-Friend-Ambiguisebaseclass/UAVBody.cpp: -------------------------------------------------------------------------------- 1 | #include "UAVBody.h" 2 | 3 | 4 | UAVBody::UAVBody() { 5 | //void UAVBody::missionGeneration() { 6 | 7 | } 8 | 9 | UAVBody::UAVBody(const UAVBody& uavBody){// II. COPY CONSTRUCTOR 10 | 11 | } 12 | UAVBody &UAVBody::operator=(const UAVBody& uavBody){// III. COPY ASSIGNMENT 13 | 14 | } 15 | 16 | UAVBody::~UAVBody() { 17 | //void UAVBody::missionGeneration() { 18 | 19 | } 20 | 21 | void UAVBody::flyOperations() { 22 | std::cout<<"Fly Operations is processed"< 2 | //Author : Burak Dogancay 3 | template 4 | struct factorial 5 | { 6 | enum 7 | { 8 | value = n * factorial::value 9 | }; 10 | 11 | }; 12 | 13 | template<> 14 | struct factorial<0> 15 | { 16 | enum { value = 1 }; 17 | }; -------------------------------------------------------------------------------- /05.Metaprogramming/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Meta.h" 2 | int main(){ 3 | std::cout<<"Factorial : "<::value< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | //Author : Burak Dogancay 8 | class MultiThread 9 | { 10 | public: 11 | MultiThread(); 12 | ~MultiThread(); 13 | void threadManagement1(); 14 | void threadManagement2(); 15 | void threadLambda(); 16 | 17 | void incrementFunc1(); 18 | void incrementFunc2(); 19 | void incrementAtomic1(); 20 | void incrementAtomic2(); 21 | 22 | 23 | private: 24 | std::mutex mMutex; 25 | int mincrement; 26 | std::atomic increment; 27 | }; -------------------------------------------------------------------------------- /06.MultiThreading/ThreadingExample/ThreadBaseClass.cpp: -------------------------------------------------------------------------------- 1 | #include "ThreadBaseClass.h" 2 | ThreadBaseClass::ThreadBaseClass() 3 | { 4 | 5 | } 6 | 7 | ThreadBaseClass::~ThreadBaseClass(){ 8 | } 9 | 10 | void ThreadBaseClass::init(){ 11 | //thread implementation will be here to call update function 12 | static std::future tBaseThread; 13 | tBaseThread = std::async(std::launch::async,&ThreadBaseClass::update,this); 14 | setMainThread(&tBaseThread); 15 | } 16 | 17 | void ThreadBaseClass::update() { 18 | while(true){ 19 | const std::lock_guard tMainMutex(mMutex); 20 | someOtherFunctions(); 21 | tickUpdate(); 22 | std::this_thread::sleep_for(std::chrono::milliseconds(200)); 23 | } 24 | } 25 | 26 | void ThreadBaseClass::setMainThread(std::future *pThread){ 27 | 28 | if(mBaseThread==pThread) 29 | return; 30 | mBaseThread = pThread; 31 | } 32 | 33 | std::future*ThreadBaseClass::getMainThread() const{ 34 | return mBaseThread; 35 | } 36 | -------------------------------------------------------------------------------- /06.MultiThreading/ThreadingExample/ThreadBaseClass.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/06.MultiThreading/ThreadingExample/ThreadBaseClass.exe -------------------------------------------------------------------------------- /06.MultiThreading/ThreadingExample/ThreadBaseClass.h: -------------------------------------------------------------------------------- 1 | #ifndef THREADBASECLASS_H 2 | #define THREADBASECLASS_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | //Author : Burak Dogancay 8 | class ThreadBaseClass 9 | { 10 | public: 11 | ThreadBaseClass(); 12 | virtual ~ThreadBaseClass(); 13 | 14 | virtual void init(); 15 | virtual void update(); 16 | virtual void tickUpdate()=0; // pure virtual function that make it abstractclass, it should be used for safety,because it should be created in all derived class 17 | virtual void someOtherFunctions()=0; 18 | 19 | void setMainThread(std::future *pThread); 20 | std::future* getMainThread() const; 21 | 22 | private: 23 | std::mutex mMutex; 24 | std::future *mBaseThread; 25 | int mThreadMillisecond = 1000; 26 | }; 27 | 28 | #endif -------------------------------------------------------------------------------- /06.MultiThreading/ThreadingExample/UavBaykarContrDerived.cpp: -------------------------------------------------------------------------------- 1 | #include "UavBaykarContrDerived.h" 2 | UavBaykarContrDerived::UavBaykarContrDerived() 3 | { 4 | 5 | } 6 | 7 | UavBaykarContrDerived::~UavBaykarContrDerived() 8 | { 9 | 10 | } 11 | 12 | void UavBaykarContrDerived::tickUpdate(){ 13 | showUavInfos(); 14 | } 15 | 16 | void UavBaykarContrDerived::someOtherFunctions(){ 17 | bayKarInfo(); 18 | } 19 | 20 | void UavBaykarContrDerived::showUavInfos(){ 21 | std::cout<<"Baykar Makina"< uavControllerBaykar = std::make_unique(); 6 | std::unique_ptr uavControllerTai = std::make_unique(); 7 | uavControllerBaykar.get()->init(); 8 | uavControllerTai.get()->init(); 9 | 10 | //The get member function waits until the future has a valid result and (depending on which template is used) retrieves it. 11 | //It effectively calls wait() in order to wait for the result. 12 | uavControllerBaykar.get()->getMainThread()->get(); 13 | uavControllerTai.get()->getMainThread()->get(); 14 | } -------------------------------------------------------------------------------- /06.MultiThreading/ThreadingExample/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/06.MultiThreading/ThreadingExample/main.exe -------------------------------------------------------------------------------- /06.MultiThreading/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Multithread.h" 2 | 3 | int main(){ 4 | MultiThread *multiThread = new MultiThread(); 5 | multiThread->threadManagement1(); 6 | //multiThread->threadManagement2(); 7 | //multiThread->threadLambda(); 8 | delete multiThread; 9 | 10 | //INTEGRATE CHAPTER 83,84,85,86,87,88,89 11 | } -------------------------------------------------------------------------------- /06.MultiThreading/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/06.MultiThreading/main.exe -------------------------------------------------------------------------------- /07.mutable-friend-type-linkedList/LinkedList/List.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_H 2 | #define LIST_H 3 | 4 | #include 5 | #include 6 | #include "ListNode.h" 7 | #include "ListNode.cpp" 8 | 9 | //Enum and struct also keyword" 10 | 11 | class List 12 | { 13 | public: 14 | List(); 15 | List(const List &ruleOfThree); // II. COPY CONSTRUCTOR 16 | List &operator=(const List &ruleOfThree); // III. COPY ASSIGNMENT 17 | ~List(); 18 | 19 | ListNode *head; 20 | void insertAtBegin(int val); 21 | void insertAtEnd(int val); 22 | void insertAtPos(int pos,int val); 23 | void remove(int toBeRemoved); 24 | void print(); 25 | 26 | 27 | 28 | }; 29 | #endif -------------------------------------------------------------------------------- /07.mutable-friend-type-linkedList/LinkedList/ListNode.cpp: -------------------------------------------------------------------------------- 1 | #include "ListNode.h" 2 | 3 | ListNode::ListNode(){ 4 | 5 | } 6 | 7 | ListNode::ListNode(int val) : //Initializer list 8 | data(val), 9 | next(NULL) 10 | { 11 | } 12 | 13 | ListNode::~ListNode(){ 14 | 15 | } 16 | 17 | ListNode::ListNode(const ListNode &ruleOfThree){ 18 | 19 | } 20 | 21 | ListNode &ListNode::operator=(const ListNode &ruleOfThree) 22 | { 23 | 24 | } 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /07.mutable-friend-type-linkedList/LinkedList/ListNode.h: -------------------------------------------------------------------------------- 1 | #ifndef LISTNODE_H 2 | #define LISTNODE_H 3 | 4 | #include 5 | #include 6 | 7 | //Enum and struct also keyword" 8 | class ListNode 9 | { 10 | public: 11 | ListNode(); 12 | ListNode(int val); 13 | ListNode(const ListNode &ruleOfThree); // II. COPY CONSTRUCTOR 14 | ListNode &operator=(const ListNode &ruleOfThree); // III. COPY ASSIGNMENT 15 | ~ListNode(); 16 | 17 | int data; 18 | ListNode *next; 19 | 20 | 21 | }; 22 | #endif -------------------------------------------------------------------------------- /07.mutable-friend-type-linkedList/Type/BasicTypeKeyword.cpp: -------------------------------------------------------------------------------- 1 | #include "BasicTypeKeyword.h" 2 | 3 | BasicTypeKeyword::BasicTypeKeyword() 4 | { 5 | } 6 | 7 | BasicTypeKeyword::BasicTypeKeyword(int val) 8 | { 9 | } 10 | 11 | BasicTypeKeyword::~BasicTypeKeyword() 12 | { 13 | } 14 | 15 | BasicTypeKeyword::BasicTypeKeyword(const BasicTypeKeyword &ruleOfThree) 16 | { 17 | } 18 | 19 | BasicTypeKeyword &BasicTypeKeyword::operator=(const BasicTypeKeyword &ruleOfThree) 20 | { 21 | } 22 | 23 | void BasicTypeKeyword::basicTypeKeywordProcess() 24 | { 25 | BasicKeywordStr basicTypeKeyword; 26 | 27 | std::cout << "All variables : " << basicTypeKeyword.intValue << " , " << basicTypeKeyword.charZero << " , " 28 | << basicTypeKeyword.floatVal << " , " << basicTypeKeyword.doubleVal << " , " 29 | << basicTypeKeyword.longVal << " , " << basicTypeKeyword.shortVal << " , " 30 | << basicTypeKeyword.boolVal << " , " << *basicTypeKeyword.message << " , " 31 | << *basicTypeKeyword.fullhouse << " , " << *basicTypeKeyword.widesetcharacters << std::endl; 32 | } 33 | -------------------------------------------------------------------------------- /07.mutable-friend-type-linkedList/Type/BasicTypeKeyword.h: -------------------------------------------------------------------------------- 1 | #ifndef BASICTYPEKEYWORD_H 2 | #define BASICTYPEKEYWORD_H 3 | 4 | #include 5 | #include 6 | 7 | //Enum and struct also keyword" 8 | class BasicTypeKeyword 9 | { 10 | public: 11 | BasicTypeKeyword(); 12 | BasicTypeKeyword(int val); 13 | BasicTypeKeyword(const BasicTypeKeyword &ruleOfThree); // II. COPY CONSTRUCTOR 14 | BasicTypeKeyword &operator=(const BasicTypeKeyword &ruleOfThree); // III. COPY ASSIGNMENT 15 | ~BasicTypeKeyword(); 16 | 17 | void basicTypeKeywordProcess(); 18 | 19 | struct BasicKeywordStr{ 20 | char charZero; //It is implementation-defined whether char is signed (and has a range of at least -127 to +127, inclusive, 8 bit val 21 | int intValue; 22 | float floatVal; 23 | double doubleVal; 24 | long longVal; // 32 bit val 25 | short shortVal; //16bit val 26 | bool boolVal; //boolean val 27 | wchar_t *widesetcharacters;//An integer type large enough to represent all characters of the largest supported extended character set, also known as the wide-character set. 28 | char16_t *message;//An unsigned integer type with the same size and alignment as uint_least16_t, 29 | char32_t *fullhouse;//range includes at least -32767 to +32767, inclusive 30 | 31 | BasicKeywordStr(){ 32 | charZero = 0; 33 | intValue = 2; 34 | floatVal = 3.145f; 35 | doubleVal = 3.1243545; 36 | longVal = 26; 37 | shortVal = 55; 38 | boolVal = false; 39 | message = u"process\n\r"; 40 | fullhouse = U"process"; 41 | widesetcharacters = L"you can write anything you watn for wchar_T"; 42 | } 43 | }; 44 | 45 | }; 46 | #endif -------------------------------------------------------------------------------- /07.mutable-friend-type-linkedList/Type/VariableDeclerationKeyword.h: -------------------------------------------------------------------------------- 1 | #ifndef VARIABLEDECLERATIONKEYWORD_H 2 | #define VARIABLEDECLERATIONKEYWORD_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | //Enum and struct also keyword" 9 | class VariableDeclerationKeyword 10 | { 11 | public: 12 | VariableDeclerationKeyword(); 13 | VariableDeclerationKeyword(int val); 14 | VariableDeclerationKeyword(const VariableDeclerationKeyword &ruleOfThree); // II. COPY CONSTRUCTOR 15 | VariableDeclerationKeyword &operator=(const VariableDeclerationKeyword &ruleOfThree); // III. COPY ASSIGNMENT 16 | ~VariableDeclerationKeyword(); 17 | 18 | //DECLERATION TYPE 19 | void declerationTypeExample(); 20 | 21 | //CONST TYPE 22 | void constantTypeExample(); 23 | 24 | //VOLATILE TYPE 25 | char memory_mapped_port; 26 | void volatileTypeExample(int x); 27 | 28 | //SIGNED TYPE 29 | void signedTypeExample(); 30 | 31 | private: 32 | struct S { 33 | void f(); 34 | void g() const; 35 | }; 36 | 37 | 38 | }; 39 | #endif -------------------------------------------------------------------------------- /07.mutable-friend-type-linkedList/Type/typekeyword.cpp: -------------------------------------------------------------------------------- 1 | #include "typekeyword.h" 2 | 3 | TypeKeyword::TypeKeyword(){ 4 | 5 | } 6 | 7 | TypeKeyword::TypeKeyword(int val) 8 | { 9 | 10 | } 11 | 12 | TypeKeyword::~TypeKeyword(){ 13 | 14 | } 15 | 16 | TypeKeyword::TypeKeyword(const TypeKeyword &ruleOfThree){ 17 | 18 | } 19 | 20 | TypeKeyword &TypeKeyword::operator=(const TypeKeyword &ruleOfThree) 21 | { 22 | 23 | 24 | } 25 | 26 | void TypeKeyword::enumOperation(){ 27 | Direction d = Direction::UP; 28 | 29 | std::cout<<"Enum type is identified and initial value is : "<< d<(sigVal.sival_ptr) << std::endl; //reinterpret cast is to convert function pointer to int type 52 | } 53 | -------------------------------------------------------------------------------- /07.mutable-friend-type-linkedList/Type/typekeyword.h: -------------------------------------------------------------------------------- 1 | #ifndef TYPEKEYWORD_H 2 | #define TYPEKEYWORD_H 3 | 4 | #include 5 | #include 6 | 7 | //Enum and struct also keyword" 8 | class TypeKeyword 9 | { 10 | public: 11 | TypeKeyword(); 12 | TypeKeyword(int val); 13 | TypeKeyword(const TypeKeyword &ruleOfThree); // II. COPY CONSTRUCTOR 14 | TypeKeyword &operator=(const TypeKeyword &ruleOfThree); // III. COPY ASSIGNMENT 15 | ~TypeKeyword(); 16 | void enumOperation(); 17 | void enumClassOperation(); 18 | void structOperation(); 19 | void structOperation2(); 20 | void unionOperation(); 21 | 22 | //Enum type Keyword 23 | enum Direction{ 24 | UP, 25 | LEFT, 26 | DOWN, 27 | RIGHT 28 | }; 29 | 30 | //Enum type class Keyword: In C++11, enum may optionally be followed by class or struct to define a scoped enum. Furthermore, both scoped 31 | //and unscoped enums can have their underlying type explicitly specified by : T following the enum name, where T 32 | //refers to an integer type 33 | enum class Format : char { 34 | TEXT = 'B', 35 | TEXT1 = 'U', 36 | TEXT2 = 'R', 37 | TEXT3 = 'A', 38 | TEXT4 = 'K' 39 | }; 40 | 41 | typedef struct somethingStruct 42 | { 43 | char variable1[6]; 44 | int variable2; 45 | somethingStruct(){ 46 | variable1[0] = 'B'; 47 | variable2 = 25; 48 | } 49 | /* data */ 50 | }; 51 | 52 | struct SomethingStruct2{ 53 | int variable; 54 | int variable2; 55 | SomethingStruct2(){ 56 | variable = 50; 57 | variable2 = 100; 58 | } 59 | }somethingStruct2; 60 | 61 | // 62 | union Sigval{ 63 | int sival_int; 64 | void *sival_ptr; 65 | }; 66 | 67 | }; 68 | #endif -------------------------------------------------------------------------------- /07.mutable-friend-type-linkedList/friend.cpp: -------------------------------------------------------------------------------- 1 | #include "friend.h" 2 | 3 | FriendClass::FriendClass(){ 4 | 5 | } 6 | 7 | FriendClass::FriendClass(int val) : 8 | private_value(val) 9 | { 10 | 11 | } 12 | 13 | FriendClass::~FriendClass(){ 14 | 15 | } 16 | 17 | FriendClass::FriendClass(const FriendClass &ruleOfThree){ 18 | 19 | } 20 | 21 | FriendClass &FriendClass::operator=(const FriendClass &ruleOfThree) 22 | { 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /07.mutable-friend-type-linkedList/friend.h: -------------------------------------------------------------------------------- 1 | #ifndef FRIEND_H 2 | #define FRIEND_H 3 | 4 | #include 5 | #include 6 | #include "friendcall.h" 7 | //Author : Burak Dogancay 8 | class FriendClass 9 | { 10 | public: 11 | FriendClass(); 12 | FriendClass(int val); 13 | FriendClass(const FriendClass &ruleOfThree); // II. COPY CONSTRUCTOR 14 | FriendClass &operator=(const FriendClass &ruleOfThree); // III. COPY ASSIGNMENT 15 | ~FriendClass(); 16 | 17 | private: 18 | //Friend Function 19 | friend void FriendCall::friend_function(); //friend function definition, therefore this function can access to the private value of this class 20 | friend FriendCall; // friend class , this class can acess to the private values of this class 21 | int private_value; 22 | 23 | int private_value_int1; 24 | int private_value_int2; 25 | std::string private_value_string1; 26 | std::string private_value_string2; 27 | }; 28 | #endif -------------------------------------------------------------------------------- /07.mutable-friend-type-linkedList/friendcall.cpp: -------------------------------------------------------------------------------- 1 | #include "friendcall.h" 2 | #include "friend.h" 3 | FriendCall::FriendCall(){ 4 | 5 | } 6 | 7 | FriendCall::~FriendCall(){ 8 | 9 | } 10 | 11 | FriendCall::FriendCall(const FriendCall &ruleOfThree){ 12 | 13 | } 14 | 15 | FriendCall &FriendCall::operator=(const FriendCall &ruleOfThree) 16 | { 17 | 18 | 19 | } 20 | 21 | void FriendCall::write_private_variables(){ 22 | FriendClass friendClass; 23 | friendClass.private_value_int1 = 10; 24 | friendClass.private_value_int2 = 20; 25 | friendClass.private_value_string1 = "String1 defined"; 26 | friendClass.private_value_string2 = "String2 defined"; 27 | 28 | std::cout<<" Variable 1 : " << friendClass.private_value_int1 29 | <<" Variable 2 : " << friendClass.private_value_int2 30 | <<" String Variable 1 :" << friendClass.private_value_string1 31 | <<" String Variable 2 : " << friendClass.private_value_string2< 5 | #include 6 | //Author : Burak Dogancay 7 | class FriendCall 8 | { 9 | public: 10 | FriendCall(); 11 | FriendCall(const FriendCall &ruleOfThree); // II. COPY CONSTRUCTOR 12 | FriendCall &operator=(const FriendCall &ruleOfThree); // III. COPY ASSIGNMENT 13 | ~FriendCall(); 14 | 15 | void friend_function(); 16 | void write_private_variables(); 17 | void non_friend_function(); 18 | 19 | 20 | }; 21 | #endif -------------------------------------------------------------------------------- /07.mutable-friend-type-linkedList/main.cpp: -------------------------------------------------------------------------------- 1 | #include "friendcall.h" 2 | #include "Type/typekeyword.h" 3 | #include "Type/BasicTypeKeyword.h" 4 | #include "Type/VariableDeclerationKeyword.h" 5 | #include "LinkedList/List.h" 6 | 7 | #include "Type/typekeyword.cpp" 8 | #include "Type/BasicTypeKeyword.cpp" 9 | #include "Type/VariableDeclerationKeyword.cpp" 10 | #include "LinkedList/List.cpp" 11 | 12 | int main() 13 | { 14 | FriendCall friendcall; 15 | TypeKeyword typedefKeyword; 16 | BasicTypeKeyword basicTypeKeyword; 17 | VariableDeclerationKeyword variableDeclerationKeyword; 18 | List linkedList; 19 | 20 | int variable = 20; 21 | 22 | /* friendcall.friend_function(); 23 | friendcall.write_private_variables(); */ 24 | 25 | //Type keywords like class,enum,struct 26 | typedefKeyword.enumOperation(); 27 | typedefKeyword.enumClassOperation(); 28 | typedefKeyword.structOperation(); 29 | typedefKeyword.structOperation2(); 30 | typedefKeyword.unionOperation(); 31 | 32 | //Basic typewords 33 | basicTypeKeyword.basicTypeKeywordProcess(); 34 | 35 | //Decleration type keyword 36 | variableDeclerationKeyword.declerationTypeExample(); 37 | variableDeclerationKeyword.constantTypeExample(); 38 | variableDeclerationKeyword.volatileTypeExample(variable); 39 | variableDeclerationKeyword.signedTypeExample(); 40 | 41 | //LinkedListExamples 42 | linkedList.insertAtEnd(20); 43 | linkedList.insertAtEnd(35); 44 | linkedList.insertAtEnd(45); 45 | linkedList.print(); */ 46 | 47 | } -------------------------------------------------------------------------------- /07.mutable-friend-type-linkedList/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/07.mutable-friend-type-linkedList/main.exe -------------------------------------------------------------------------------- /07.mutable-friend-type-linkedList/mutable.cpp: -------------------------------------------------------------------------------- 1 | #include "mutable.h" 2 | 3 | MutableClass::MutableClass() 4 | { 5 | } 6 | 7 | MutableClass::MutableClass(const MutableClass &ruleOfThree) 8 | { 9 | } 10 | 11 | MutableClass::~MutableClass() 12 | { 13 | } 14 | 15 | MutableClass &MutableClass::operator=(const MutableClass &ruleOfThree) 16 | { 17 | } 18 | 19 | void MutableClass::mutableLambdas() 20 | { 21 | 22 | /*By default, the implicit operator() of a lambda is const. This disallows performing non-const operations on the 23 | lambda. In order to allow modifying members, a lambda may be marked mutable, which makes the implicit 24 | operator() non-const:*/ 25 | 26 | int a = 0; 27 | /* 28 | std::function bad_counter = [a] { 29 | return a++; // error: operator() is const 30 | // cannot modify members 31 | }; 32 | */ 33 | 34 | std::function good_counter = [a]() mutable { 35 | return a++; // OK 36 | }; 37 | 38 | std::cout << good_counter() << std::endl; // 0 39 | std::cout << good_counter() << std::endl; // 1 40 | std::cout << good_counter() << std::endl; // 2 41 | } 42 | 43 | double MutableClass::getPi() const 44 | { 45 | if (pi_calculated) 46 | { 47 | return pi; 48 | } 49 | else 50 | { 51 | double new_pi = 0; 52 | for (int i = 0; i < 10; ++i) 53 | { 54 | // some calculation to refine new_pi 55 | new_pi += i; 56 | 57 | } 58 | // note: if pi and pi_calculated were not mutable, we would get an error from a compiler 59 | // because in a const method we can not change a non-mutable field 60 | pi = new_pi; 61 | pi_calculated = true; 62 | std::cout<<"P Value is : "< 5 | #include 6 | //Author : Burak Dogancay 7 | class MutableClass 8 | { 9 | public: 10 | MutableClass(); 11 | MutableClass(const MutableClass &ruleOfThree); // II. COPY CONSTRUCTOR 12 | MutableClass &operator=(const MutableClass &ruleOfThree); // III. COPY ASSIGNMENT 13 | ~MutableClass(); 14 | 15 | void mutableLambdas(); 16 | double getPi() const; 17 | 18 | private: 19 | mutable bool pi_calculated = false; 20 | mutable bool pi = 0; 21 | }; 22 | #endif -------------------------------------------------------------------------------- /08.Overload-NestedClass-Explicit/Overload-NestedClass-Explicit.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/08.Overload-NestedClass-Explicit/Overload-NestedClass-Explicit.exe -------------------------------------------------------------------------------- /08.Overload-NestedClass-Explicit/Overload-NestedClass-Explicit.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | //Author : Burak Dogancay 8 | //NESTED CLASS EXAMPLE 9 | class ExampleClass1 10 | { 11 | public: 12 | class ExampleClass2 13 | { 14 | 15 | public: 16 | ExampleClass2(); 17 | explicit ExampleClass2(int a); 18 | ~ExampleClass2(); // I DESTRUCTOR 19 | 20 | //PASS BY EXAMPLES 21 | void passbyReference(int &pValue); 22 | void passbyValue(int pValue); 23 | void passbyPointer(int *pValue); 24 | 25 | //OVERLOADING FUNCTIONS 26 | void passbyReference(int &pValue1,int &pValue2); 27 | void passbyValue(int pValue1, int pValue2); 28 | void passbyPointer(int *pValue1, int *pValue2); 29 | 30 | //Pass by example execution 31 | void passbyExeExample(); 32 | void passbyExeOverloadExample(); 33 | 34 | //MUTABLE EXAMPLE 35 | void mutableExample(); 36 | 37 | //INLINE FUNCTIONS(This is just a suggestion to compiler to make the function inline, 38 | //if function is big (in term of executable instruction etc) then, compiler can ignore the “inline” request and treat the function as normal function.) 39 | //The inline functions are a C++ enhancement feature to increase the execution time of a program. 40 | inline void function() 41 | { 42 | int tInlineVar = 500; 43 | int *tPointerVar; 44 | tPointerVar = &tInlineVar; 45 | std::cout << "Pointer Variable : " << *tPointerVar << std::endl; 46 | } 47 | 48 | mutable int mValue; // can be changed in const getValue function because it is mutable 49 | int getValue() const; 50 | 51 | private: 52 | char *cstring; 53 | }; 54 | }; 55 | -------------------------------------------------------------------------------- /08.Overload-NestedClass-Explicit/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Overload-NestedClass-Explicit.h" 2 | #include 3 | 4 | int main(){ 5 | ExampleClass1::ExampleClass2 relatedClass; 6 | ExampleClass1::ExampleClass2 explicitClass(20); //Explicit class example 7 | 8 | int tVal = 90; 9 | ExampleClass1::ExampleClass2 explicitClass2 = static_cast(tVal); 10 | 11 | relatedClass.passbyExeExample(); 12 | relatedClass.passbyExeOverloadExample(); 13 | 14 | relatedClass.function(); 15 | 16 | const int incVariable = relatedClass.getValue(); 17 | std::cout<<"Incremented Variable : "<< incVariable << std::endl; 18 | 19 | 20 | } -------------------------------------------------------------------------------- /08.Overload-NestedClass-Explicit/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/08.Overload-NestedClass-Explicit/main.exe -------------------------------------------------------------------------------- /09.PassBy-Mutable-Inline/PassBy-Mutable-Inline.cpp: -------------------------------------------------------------------------------- 1 | #include "PassBy-Mutable-Inline.h" 2 | PassByExample::PassByExample() : mValue(0) 3 | { 4 | } 5 | 6 | PassByExample::~PassByExample() //DESTRUCTOR 7 | { 8 | } 9 | //Pvalue is the reference of passed value therefore if pValue is changed mValue will be changed too 10 | void PassByExample::passbyReference(int &pValue) 11 | { 12 | std::cout << "Before changing Integer Value : " << pValue << std::endl; 13 | pValue = 40; 14 | std::cout << "After changing Integer Integer Value : " << pValue << std::endl; 15 | } 16 | void PassByExample::passbyValue(int pValue) 17 | { 18 | int tValue = pValue; 19 | pValue = 50; 20 | std::cout << "Integer Value : " << tValue << pValue << std::endl; 21 | } 22 | 23 | void PassByExample::passbyPointer(int *pValue) 24 | { 25 | *pValue = 100; 26 | std::cout << "Integer Value : " << *pValue << std::endl; 27 | } 28 | 29 | void PassByExample::passbyExeExample() 30 | { 31 | int tValue = 80; 32 | passbyReference(tValue); 33 | passbyValue(tValue); 34 | passbyPointer(&tValue); 35 | } 36 | 37 | int PassByExample::getValue() const 38 | { 39 | mValue++; 40 | return mValue; 41 | } 42 | -------------------------------------------------------------------------------- /09.PassBy-Mutable-Inline/PassBy-Mutable-Inline.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | //Author : Burak Dogancay 7 | class PassByExample 8 | { 9 | 10 | public: 11 | PassByExample(); 12 | ~PassByExample(); // I DESTRUCTOR 13 | 14 | //PASS BY EXAMPLES 15 | void passbyReference(int &pValue); 16 | void passbyValue(int pValue); 17 | void passbyPointer(int *pValue); 18 | 19 | //Pass by example execution 20 | void passbyExeExample(); 21 | 22 | //MUTABLE EXAMPLE 23 | void mutableExample(); 24 | 25 | //INLINE FUNCTIONS(This is just a suggestion to compiler to make the function inline, 26 | //if function is big (in term of executable instruction etc) then, compiler can ignore the “inline” request and treat the function as normal function.) 27 | //The inline functions are a C++ enhancement feature to increase the execution time of a program. 28 | inline void function() 29 | { 30 | int tInlineVar = 500; 31 | int *tPointerVar; 32 | tPointerVar = &tInlineVar; 33 | std::cout << "Pointer Variable : " << *tPointerVar < 3 | 4 | int main(){ 5 | PassByExample relatedClass; 6 | 7 | relatedClass.passbyExeExample(); 8 | 9 | relatedClass.function(); 10 | 11 | const int incVariable = relatedClass.getValue(); 12 | std::cout<<"Incremented Variable : "<< incVariable << std::endl; 13 | 14 | 15 | } -------------------------------------------------------------------------------- /09.PassBy-Mutable-Inline/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/09.PassBy-Mutable-Inline/main.exe -------------------------------------------------------------------------------- /10.Pointer_example-Singleton/main.cpp: -------------------------------------------------------------------------------- 1 | #include "pointerclass.h" 2 | 3 | int main(){ 4 | 5 | std::cout<<"Workşing well"<pointercheckbyadress(*tpointerclass); //PASS CLASS POINTER TO THE FUNCTION WITH PASS BY POINTER 9 | return 0; 10 | } -------------------------------------------------------------------------------- /10.Pointer_example-Singleton/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/10.Pointer_example-Singleton/main.exe -------------------------------------------------------------------------------- /10.Pointer_example-Singleton/pointerclass.cpp: -------------------------------------------------------------------------------- 1 | #include "pointerclass.h" 2 | 3 | pointerclass::pointerclass() : mpointerval(20){ 4 | 5 | 6 | } 7 | 8 | pointerclass::~pointerclass(){ 9 | 10 | 11 | } 12 | 13 | pointerclass *pointerclass::instance(){ 14 | static pointerclass tpointerclass; 15 | return &tpointerclass; 16 | } 17 | 18 | void pointerclass::pointercheckbyadress(const pointerclass &pclass){ 19 | std::cout << pclass.mpointerval << std::endl; 20 | } -------------------------------------------------------------------------------- /10.Pointer_example-Singleton/pointerclass.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | //Author : Burak Dogancay 5 | class pointerclass 6 | { 7 | private: 8 | /* data */ 9 | int mpointerval; 10 | 11 | public: 12 | pointerclass(/* args */); 13 | static pointerclass *instance(); 14 | void pointercheckbyadress(const pointerclass &pclass); 15 | ~pointerclass(); 16 | }; 17 | 18 | 19 | -------------------------------------------------------------------------------- /11.ReturnSeveralValues/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/11.ReturnSeveralValues/main.exe -------------------------------------------------------------------------------- /12.RuleOfFive-RuleofThree/RuleofFive-Ruleofthree.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | //Author : Burak Dogancay 7 | //Rule of three : destructor, copy constructor, copy assignment 8 | class RuleOfThree 9 | { 10 | 11 | public: 12 | RuleOfThree(); 13 | RuleOfThree (const char* s); 14 | ~RuleOfThree(); // I DESTRUCTOR 15 | RuleOfThree(const RuleOfThree& ruleOfThree);// II. COPY CONSTRUCTOR 16 | RuleOfThree& operator=(const RuleOfThree& ruleOfThree);// III. COPY ASSIGNMENT 17 | 18 | 19 | private: 20 | char *cstring; 21 | RuleOfThree(const char *s, std::size_t n); 22 | 23 | public: 24 | operator const char *() const{return cstring;} 25 | }; 26 | 27 | 28 | //Rule of Five: destructor , copy constructor, move constructor, copy assignment operator, move assignment 29 | class RuleOfFive 30 | { 31 | public: 32 | 33 | RuleOfFive(); 34 | RuleOfFive (const char* string); 35 | ~RuleOfFive();// I DESTRUCTOR 36 | RuleOfFive(const RuleOfFive& ruleOfFive);// II. COPY CONSTRUCTOR 37 | RuleOfFive(RuleOfFive&& ruleOfFive) noexcept;//III. MOVE CONSTRUCTOR 38 | RuleOfFive& operator=(const RuleOfFive& ruleOfFive);// IV COPY ASSIGNMENT 39 | RuleOfFive& operator=(RuleOfFive&& ruleOfFive) noexcept; // V. MOVE ASSIGNMENT 40 | 41 | 42 | private: 43 | char *mstring; 44 | }; -------------------------------------------------------------------------------- /12.RuleOfFive-RuleofThree/main.cpp: -------------------------------------------------------------------------------- 1 | #include "RuleofFive-Ruleofthree.h" 2 | #include 3 | // void ruleOfFive(){ 4 | // RuleOfFive o1{"abc"}; // normal constructor 5 | // std::cout << o1 << ' '; 6 | 7 | // RuleOfFive o2{ o1 }; // I. uses copy constructor 8 | // std::cout << o2 << ' '; 9 | 10 | // RuleOfFive o3("def"); 11 | // std::cout << o3 << ' '; 12 | 13 | // o3 = o2; // III. uses copy assignment 14 | // std::cout << o3 << ' '; 15 | // } 16 | 17 | void ruleOfThree(){ 18 | RuleOfThree o1{"abc"}; // normal constructor 19 | std::cout << o1 << ' '; 20 | 21 | auto o2{ o1 }; // I. uses copy constructor 22 | std::cout << o2 << ' '; 23 | 24 | RuleOfThree o3("def"); 25 | std::cout << o3 << ' '; 26 | 27 | o3 = o2; // III. uses copy assignment 28 | std::cout << o3 << ' '; 29 | } 30 | 31 | int main(){ 32 | 33 | ruleOfThree(); 34 | 35 | } -------------------------------------------------------------------------------- /12.RuleOfFive-RuleofThree/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/12.RuleOfFive-RuleofThree/main.exe -------------------------------------------------------------------------------- /13.Smartptr-Lambda-Movesemantics-const/ConstExamples.cpp: -------------------------------------------------------------------------------- 1 | #include "ConstExamples.h" 2 | ConstExamples::ConstExamples() 3 | { 4 | 5 | } 6 | //In code above, we call const version of GetBar from the non-const GetBar by casting this to const type: 7 | //const_cast(this). Since we call const method from non-const, the object itself is non-const, and 8 | //casting away the const is allowed 9 | char &ConstExamples::GetScore(bool midterm) 10 | { 11 | return const_cast(const_cast(this)->GetScore(midterm)); 12 | } 13 | 14 | const char &ConstExamples::GetScore(bool midterm) const 15 | { 16 | if (midterm) 17 | { 18 | return midtermScore; 19 | } 20 | else 21 | { 22 | return finalScore; 23 | } 24 | } 25 | 26 | int ConstExamples::getIntegerVal() const{ 27 | return myInt; 28 | } 29 | 30 | void ConstExamples::setIntegerVal(int &MyInt){ 31 | myInt = MyInt; 32 | } 33 | 34 | ConstExamples::~ConstExamples(){ 35 | 36 | } -------------------------------------------------------------------------------- /13.Smartptr-Lambda-Movesemantics-const/ConstExamples.h: -------------------------------------------------------------------------------- 1 | #ifndef CONSTEXAMPLES_H 2 | #define CONSTEXAMPLES_H 3 | #include 4 | //Author : Burak Dogancay 5 | class ConstExamples{ 6 | public : 7 | ConstExamples(); 8 | ~ConstExamples(); 9 | char& GetScore(bool midterm); 10 | const char& GetScore(bool midterm) const; 11 | 12 | //Member functions of a class can be declared const, which tells the compiler and future readers that this function 13 | //will not modify the object: 14 | int getIntegerVal() const;//for reading variable 15 | void setIntegerVal(int &MyInt);//set variable 16 | 17 | //Static variables 18 | static int staticIntVar; 19 | static char staticCharVar; 20 | 21 | private: 22 | char midtermScore; 23 | char finalScore; 24 | int myInt; 25 | 26 | }; 27 | 28 | #endif -------------------------------------------------------------------------------- /13.Smartptr-Lambda-Movesemantics-const/MoveSemantics-Struct-CopyCostruct.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "ConstExamples.h" 5 | #include 6 | class MoveSemantics 7 | { 8 | public: 9 | //Move semantics means the class will transfer ownership of the object rather than making copy 10 | MoveSemantics(); 11 | MoveSemantics(const MoveSemantics& movesemantics); //A user-defined copy constructor is generally needed when an object owns pointers or non-shareable references, 12 | //such as to a file, in which case a destructor and an assignment operator should also be written (see Rule of three). 13 | ~MoveSemantics(); 14 | void moveSemanticsExample(); 15 | void moveSemanticsStruct(); 16 | void typedefStructcheck(); 17 | void normalStructCheck(); 18 | void callStruct(void *fun); 19 | void callStaticVariables(); 20 | 21 | //Used for copy constructor 22 | int x; 23 | int y; 24 | 25 | private: 26 | //struct is normmaly public but class is normally private 27 | typedef struct typedefstruct 28 | { 29 | int xVar; 30 | int yVar; 31 | int zVar; 32 | typedefstruct() 33 | { 34 | xVar = 50; 35 | yVar = 100; 36 | zVar = 200; 37 | } 38 | }; 39 | 40 | struct normalstruct 41 | { 42 | int xVar; 43 | int yVar; 44 | 45 | normalstruct() 46 | { 47 | xVar = 100; 48 | yVar = 450; 49 | } 50 | }; 51 | 52 | ConstExamples *mConstClass; 53 | ConstExamples *mConstClasstrans; 54 | typedefstruct *mTypedefStruct; 55 | }; -------------------------------------------------------------------------------- /13.Smartptr-Lambda-Movesemantics-const/SmartPointers-Lambda.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "ConstExamples.h" 4 | #include 5 | class SmartPointers 6 | { 7 | public: 8 | SmartPointers(); 9 | ~SmartPointers(); 10 | void conditionalOperator(); 11 | double lambdaexample(); 12 | double lambdaexample2(int pParam); 13 | 14 | //Another lambda example 15 | int x,y; 16 | int operator()(int); 17 | void lambdaexample3(); 18 | 19 | //Lambda Definitions 20 | void lambdaDef(int i); 21 | void lambdaDef2(int i); 22 | 23 | //SmartPointers 24 | //Smart pointers are used to avoid memory leaks which is occured in dunamic memory allocation 25 | std::shared_ptr mConstExampSh; 26 | std::unique_ptr mConstExampUn; 27 | private: 28 | double mDoubleVar; 29 | }; -------------------------------------------------------------------------------- /13.Smartptr-Lambda-Movesemantics-const/main.cpp: -------------------------------------------------------------------------------- 1 | #include "SmartPointers-Lambda.h" 2 | #include "MoveSemantics-Struct-CopyCostruct.h" 3 | 4 | void constexample(){ 5 | ConstExamples consta; 6 | 7 | //// We can assign to the reference. Non-const version of GetScore is called 8 | consta.GetScore(true) = 'C'; 9 | consta.GetScore(false) = 'D'; 10 | 11 | const ConstExamples constb(consta); 12 | // We still can call GetScore method of const object, 13 | // because we have overloaded const version of GetScore 14 | std::cout << constb.GetScore(true) << constb.GetScore(false) << '\n'; 15 | 16 | //CONST MEMBER FUNCTIONS 17 | int myInt = 80; 18 | consta.setIntegerVal(myInt); 19 | std::cout<<"Integer val is : "<< consta.getIntegerVal() <<" "; 20 | } 21 | 22 | void smartPointersEx(){ 23 | SmartPointers smartpointerEx; 24 | smartpointerEx.conditionalOperator(); 25 | smartpointerEx.lambdaexample(); 26 | smartpointerEx.lambdaexample2(50); 27 | smartpointerEx.lambdaexample3(); 28 | } 29 | 30 | void semanticsCpyCostr(){ 31 | //Mem operations also called in this class check 32 | MoveSemantics moveSemantics; 33 | MoveSemantics moveSemantics2 (moveSemantics); // Copy constructor is called here we can also write it as "MoveSemantics moveSemantics2 = moveSemantics" COPY CONSTRUCTOR EXAMPLE 34 | moveSemantics.moveSemanticsExample(); 35 | moveSemantics.typedefStructcheck(); 36 | moveSemantics.normalStructCheck(); 37 | moveSemantics.moveSemanticsStruct(); 38 | moveSemantics.callStaticVariables(); 39 | 40 | std::cout<<"Copy constructor X and Y Values is not changed : "< 5 | #include 6 | //Author : Burak Dogancay 7 | class Mymain{ 8 | 9 | public: 10 | Mymain(); 11 | ~Mymain(); 12 | //never define static in header file , you expect one instance but it creates two if you create class 13 | static int staticdefone; 14 | static const int myStaticConstVariable = 50; 15 | 16 | private: 17 | 18 | protected: 19 | 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /15.Template-Example/Untitled1.cpp: -------------------------------------------------------------------------------- 1 | #include "Untitled1.h" 2 | template 3 | myClass::myClass()//: mvalue(20),mprivval(10) 4 | { 5 | 6 | } 7 | 8 | template 9 | myClass::myClass(T value){ 10 | mvalue = value; 11 | mprivval = value*4; 12 | 13 | doubleval = static_cast(value); 14 | doubleval2 = static_cast(value*6); 15 | doubleval3 = static_cast(value*40); 16 | } 17 | 18 | template 19 | void myClass::somemaths(){ 20 | int sum = mvalue+mprivval; 21 | int mult= mvalue*mprivval; 22 | std::cout<<"Sum and Multiply : "< 27 | T myClass::intFunction(){ 28 | int t_value= 20; 29 | std::cout<<"Function called with value : "< 34 | void myClass::writeString(T string){ 35 | std::cout<<"Type id name : "< myownclass(20); 43 | 44 | //std::cout<<"My value : "< 5 | #include 6 | #include 7 | #include 8 | //Author : Burak Dogancay 9 | template 10 | class myClass 11 | { 12 | public: 13 | myClass(); 14 | explicit myClass(T value); 15 | T mvalue; 16 | T mprivval; 17 | T intFunction(); 18 | void somemaths(); 19 | void writeString(T string); 20 | double doubleval; 21 | double doubleval2; 22 | double doubleval3; 23 | 24 | 25 | private: 26 | }; 27 | typedef myClass myClassConst; 28 | 29 | 30 | 31 | #endif -------------------------------------------------------------------------------- /15.Template-Example/vc140.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/15.Template-Example/vc140.pdb -------------------------------------------------------------------------------- /16.Pointers/PointerBasics/PointerBasics.h: -------------------------------------------------------------------------------- 1 | #ifndef POINTERBASICS_H 2 | #define POINTERBASICS_H 3 | 4 | #include 5 | #include 6 | //Author : Burak Dogancay 7 | 8 | //Enum and struct also keyword" 9 | class PointerBasics 10 | { 11 | public: 12 | PointerBasics(); 13 | PointerBasics(int val); 14 | PointerBasics(const PointerBasics &ruleOfThree); // II. COPY CONSTRUCTOR 15 | PointerBasics &operator=(const PointerBasics &ruleOfThree); // III. COPY ASSIGNMENT 16 | ~PointerBasics(); 17 | 18 | void print(); 19 | void pointerOperations(); 20 | void creatingPointerVariable(); 21 | 22 | 23 | 24 | }; 25 | #endif -------------------------------------------------------------------------------- /16.Pointers/main.cpp: -------------------------------------------------------------------------------- 1 | #include "PointerBasics/PointerBasics.h" 2 | #include 3 | 4 | #include "PointerBasics/PointerBasics.cpp" 5 | 6 | 7 | int main(){ 8 | PointerBasics pointerBasics; 9 | 10 | //Pointers basics 11 | pointerBasics.print(); 12 | pointerBasics.pointerOperations(); 13 | pointerBasics.creatingPointerVariable(); 14 | 15 | 16 | } -------------------------------------------------------------------------------- /16.Pointers/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/16.Pointers/main.exe -------------------------------------------------------------------------------- /17.ClassAndStructure/AccessSpecifier/AccessSpecifier.cpp: -------------------------------------------------------------------------------- 1 | #include "AccessSpecifier.h"" 2 | 3 | AccessSpecifier::AccessSpecifier() 4 | { 5 | } 6 | 7 | AccessSpecifier::AccessSpecifier(int val) 8 | { 9 | } 10 | 11 | AccessSpecifier::~AccessSpecifier() 12 | { 13 | } 14 | 15 | AccessSpecifier::AccessSpecifier(const AccessSpecifier &ruleOfThree) 16 | { 17 | } 18 | 19 | AccessSpecifier &AccessSpecifier::operator=(const AccessSpecifier &ruleOfThree) 20 | { 21 | } 22 | void AccessSpecifier::accessPrivateVal(){ 23 | std::cout<<"Private Valuse : "<< a <<" "<< b< 5 | #include 6 | #include 7 | //Author : Burak Dogancay 8 | //ClassBasics1 is equal to ClassBasics 9 | /* public Everyone has access 10 | protected Only the class itself, derived classes and friends have access 11 | private Only the class itself and friends have access */ 12 | 13 | //Access specifiers are mostly used to limit access to internal fields and methods, and force the programmer to use a 14 | //specific interface, for example to force use of getters and setters instead of referencing a variable directly: 15 | 16 | //Using protected is useful for allowing certain functionality of the type to be only accessible to the derived classes, 17 | class AccessSpecifier 18 | { 19 | public: 20 | AccessSpecifier(); 21 | AccessSpecifier(int val); 22 | AccessSpecifier(const AccessSpecifier &ruleOfThree); // II. COPY CONSTRUCTOR 23 | AccessSpecifier &operator=(const AccessSpecifier &ruleOfThree); // III. COPY ASSIGNMENT 24 | ~AccessSpecifier(); 25 | 26 | void accessPrivateVal(); 27 | void accessProtectedVal(); 28 | 29 | const int c = 10; 30 | 31 | private: 32 | const int a = 5; 33 | const int b = 6; 34 | 35 | protected: 36 | const int d = 20; 37 | const int e = 30; 38 | }; 39 | 40 | #endif -------------------------------------------------------------------------------- /17.ClassAndStructure/ClassBasics/ClassBasics.cpp: -------------------------------------------------------------------------------- 1 | #include "ClassBasics.h"" 2 | 3 | ClassBasics::ClassBasics() 4 | { 5 | } 6 | 7 | ClassBasics::ClassBasics(int val) 8 | { 9 | } 10 | 11 | ClassBasics::~ClassBasics() 12 | { 13 | } 14 | 15 | ClassBasics::ClassBasics(const ClassBasics &ruleOfThree) 16 | { 17 | } 18 | 19 | ClassBasics &ClassBasics::operator=(const ClassBasics &ruleOfThree) 20 | { 21 | } 22 | 23 | -------------------------------------------------------------------------------- /17.ClassAndStructure/ClassBasics/ClassBasics.h: -------------------------------------------------------------------------------- 1 | #ifndef CLASSBASICS_H 2 | #define CLASSBASICS_H 3 | 4 | #include 5 | #include 6 | #include 7 | //Author : Burak Dogancay 8 | struct ClassBasics1 9 | { 10 | /* data */ 11 | int x; 12 | int y; 13 | int z; 14 | }; 15 | 16 | //ClassBasics1 is equal to ClassBasics 17 | class ClassBasics 18 | { 19 | public: 20 | ClassBasics(); 21 | ClassBasics(int val); 22 | ClassBasics(const ClassBasics &ruleOfThree); // II. COPY CONSTRUCTOR 23 | ClassBasics &operator=(const ClassBasics &ruleOfThree); // III. COPY ASSIGNMENT 24 | ~ClassBasics(); 25 | 26 | int x; 27 | int y; 28 | int z; 29 | 30 | }; 31 | #endif -------------------------------------------------------------------------------- /17.ClassAndStructure/FinalClassAndStructs/FinalClassAndStructs.cpp: -------------------------------------------------------------------------------- 1 | #include "FinalClassAndStructs.h"" 2 | 3 | FinalClassAndStructs::FinalClassAndStructs() 4 | { 5 | } 6 | 7 | FinalClassAndStructs::FinalClassAndStructs(int val) 8 | { 9 | } 10 | 11 | FinalClassAndStructs::~FinalClassAndStructs() 12 | { 13 | } 14 | 15 | FinalClassAndStructs::FinalClassAndStructs(const FinalClassAndStructs &ruleOfThree) 16 | { 17 | } 18 | 19 | FinalClassAndStructs &FinalClassAndStructs::operator=(const FinalClassAndStructs &ruleOfThree) 20 | { 21 | } 22 | 23 | -------------------------------------------------------------------------------- /17.ClassAndStructure/FinalClassAndStructs/FinalClassAndStructs.h: -------------------------------------------------------------------------------- 1 | #ifndef FINALCLASSANDSTRUCTS_H 2 | #define FINALCLASSANDSTRUCTS_H 3 | 4 | #include 5 | #include 6 | #include 7 | //Author : Burak Dogancay 8 | //ClassBasics1 is equal to ClassBasics 9 | class FinalClassAndStructs final 10 | { 11 | public: 12 | FinalClassAndStructs(); 13 | FinalClassAndStructs(int val); 14 | FinalClassAndStructs(const FinalClassAndStructs &ruleOfThree); // II. COPY CONSTRUCTOR 15 | FinalClassAndStructs &operator=(const FinalClassAndStructs &ruleOfThree); // III. COPY ASSIGNMENT 16 | ~FinalClassAndStructs(); 17 | 18 | 19 | }; 20 | 21 | //Final class may appear anywhere in class hierarchy: 22 | class FinalClassAndStructs1 { 23 | }; 24 | 25 | // OK. 26 | class FinalClassAndStructs2 final : public FinalClassAndStructs1 { 27 | }; 28 | /* // Compilation error: cannot derive from final class B. 29 | class FinalClassAndStructs3 : public FinalClassAndStructs2 { 30 | }; */ 31 | 32 | #endif -------------------------------------------------------------------------------- /17.ClassAndStructure/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ClassBasics/ClassBasics.h" 2 | #include "FinalClassAndStructs/FinalClassAndStructs.h" 3 | #include "AccessSpecifier/AccessSpecifier.h" 4 | #include 5 | #include "ClassBasics/ClassBasics.cpp" 6 | #include "FinalClassAndStructs/FinalClassAndStructs.cpp" 7 | #include "AccessSpecifier/AccessSpecifier.cpp" 8 | int main() 9 | { 10 | ClassBasics classBasics; 11 | ClassBasics1 classBasics1; 12 | AccessSpecifier accessSpecifier; 13 | 14 | //Enter data of the classBasics 15 | classBasics.x = 20; 16 | classBasics.y = 30; 17 | classBasics.z = 50; 18 | 19 | //Enter data of the classBasics1 20 | classBasics1.x = 60; 21 | classBasics1.y = 80; 22 | classBasics1.z = 100; 23 | 24 | //print all values 25 | std::cout << "Class Basics Data : " 26 | << " " << classBasics.x << " " << classBasics.y << " " << classBasics.z << std::endl; 27 | std::cout << "Class Basics1 Data : " 28 | << " " << classBasics1.x << " " << classBasics1.y << " " << classBasics.z << std::endl; 29 | //------------------------------------------------------------ 30 | 31 | //Access Specifier 32 | std::cout<<"Public Value : "< 5 | #include 6 | #include 7 | //Author : Burak Dogancay 8 | //ClassBasics1 is equal to ClassBasics 9 | /* public Everyone has access 10 | protected Only the class itself, derived classes and friends have access 11 | private Only the class itself and friends have access */ 12 | 13 | //Access specifiers are mostly used to limit access to internal fields and methods, and force the programmer to use a 14 | //specific interface, for example to force use of getters and setters instead of referencing a variable directly: 15 | 16 | //Using protected is useful for allowing certain functionality of the type to be only accessible to the derived classes, 17 | class FunctionOverloading 18 | { 19 | public: 20 | FunctionOverloading(); 21 | FunctionOverloading(int val) = delete; 22 | FunctionOverloading(FunctionOverloading &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 23 | FunctionOverloading(const FunctionOverloading &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 24 | FunctionOverloading &operator=(const FunctionOverloading &ruleOfThree) = delete; // III. COPY ASSIGNMENT 25 | ~FunctionOverloading() = default; 26 | 27 | //-----------Function Overloading------------- 28 | void print(const std::string &pStr); 29 | void print(int pVal); 30 | void print(double pVal); 31 | //Note that you cannot overload a function based on its return type. For example: 32 | /* // WRONG CODE 33 | std::string getValue() 34 | { 35 | return "hello"; 36 | } 37 | int getValue() 38 | { 39 | return 0; 40 | } 41 | int x = getValue(); */ 42 | }; 43 | 44 | #endif -------------------------------------------------------------------------------- /18.Overloading/FunctionOverloading/FunctionOverloading.cpp: -------------------------------------------------------------------------------- 1 | #include "FunctionOverloading.h" 2 | 3 | FunctionOverloading::FunctionOverloading() 4 | { 5 | } 6 | 7 | void FunctionOverloading::print(const std::string &pStr){ 8 | std::cout<<"String Val is : "< 5 | #include 6 | #include 7 | //Author : Burak Dogancay 8 | //ClassBasics1 is equal to ClassBasics 9 | /* public Everyone has access 10 | protected Only the class itself, derived classes and friends have access 11 | private Only the class itself and friends have access */ 12 | 13 | //Access specifiers are mostly used to limit access to internal fields and methods, and force the programmer to use a 14 | //specific interface, for example to force use of getters and setters instead of referencing a variable directly: 15 | 16 | //Using protected is useful for allowing certain functionality of the type to be only accessible to the derived classes, 17 | class FunctionOverloading 18 | { 19 | public: 20 | FunctionOverloading(); 21 | FunctionOverloading(int val) = delete; 22 | FunctionOverloading(FunctionOverloading &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 23 | FunctionOverloading(const FunctionOverloading &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 24 | FunctionOverloading &operator=(const FunctionOverloading &ruleOfThree) = delete; // III. COPY ASSIGNMENT 25 | ~FunctionOverloading() = default; 26 | 27 | //-----------Function Overloading------------- 28 | void print(const std::string &pStr); 29 | void print(int pVal); 30 | void print(double pVal); 31 | //Note that you cannot overload a function based on its return type. For example: 32 | /* // WRONG CODE 33 | std::string getValue() 34 | { 35 | return "hello"; 36 | } 37 | int getValue() 38 | { 39 | return 0; 40 | } 41 | int x = getValue(); */ 42 | }; 43 | 44 | #endif -------------------------------------------------------------------------------- /18.Overloading/main.cpp: -------------------------------------------------------------------------------- 1 | #include "FunctionOverloading/FunctionOverloading.h" 2 | 3 | #include 4 | #include "FunctionOverloading/FunctionOverloading.cpp" 5 | 6 | int main() 7 | { 8 | FunctionOverloading functionOverloading; 9 | 10 | //Function Overloading 11 | functionOverloading.print("String Def"); 12 | functionOverloading.print(20); 13 | functionOverloading.print(21.5); 14 | 15 | } -------------------------------------------------------------------------------- /18.Overloading/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/18.Overloading/main.exe -------------------------------------------------------------------------------- /19.MemberFunctions/InlineFunctions/InlineFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include "InlineFunctions.h" 2 | 3 | InlineFunctions::InlineFunctions() 4 | { 5 | 6 | } 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /19.MemberFunctions/InlineFunctions/InlineFunctions.h: -------------------------------------------------------------------------------- 1 | #ifndef INLINEFUNCTIONS_H 2 | #define INLINEFUNCTIONS_H 3 | 4 | #include 5 | #include 6 | #include 7 | //Author : Burak Dogancay 8 | /* A function defined with the inline specifier is an inline function. An inline function can be multiply defined without 9 | violating the One Definition Rule, and can therefore be defined in a header with external linkage. Declaring a 10 | function inline hints to the compiler that the function should be inlined during code generation, but does not 11 | provide a guarantee. */ 12 | class InlineFunctions 13 | { 14 | public: 15 | InlineFunctions(); 16 | InlineFunctions(int val) = delete; 17 | InlineFunctions(InlineFunctions &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 18 | InlineFunctions(const InlineFunctions &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 19 | InlineFunctions &operator=(const InlineFunctions &ruleOfThree) = delete; // III. COPY ASSIGNMENT 20 | ~InlineFunctions() = default; 21 | 22 | inline void nonMemberInlineFunc(int x, int y){ 23 | std::cout<<"Inline funct definition : "< 5 | #include 6 | #include 7 | //Author : Burak Dogancay 8 | 9 | class FinalVirtualFunctionsBase 10 | { 11 | public: 12 | FinalVirtualFunctionsBase(); 13 | FinalVirtualFunctionsBase(int val) = delete; 14 | FinalVirtualFunctionsBase(FinalVirtualFunctionsBase &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 15 | FinalVirtualFunctionsBase(const FinalVirtualFunctionsBase &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 16 | FinalVirtualFunctionsBase &operator=(const FinalVirtualFunctionsBase &ruleOfThree) = delete; // III. COPY ASSIGNMENT 17 | virtual ~FinalVirtualFunctionsBase() = 0; 18 | 19 | void baseClassInformation(); 20 | inline virtual void overridingFunc(){ 21 | std::cout<<"Baseclass Overriding1"; 22 | } 23 | inline virtual void overridingFunc2(){ 24 | std::cout<<"BaseClass Overriding2"; 25 | } 26 | 27 | 28 | }; 29 | 30 | #endif -------------------------------------------------------------------------------- /19.MemberFunctions/VirtualMemberFunctions/FinalVirtualFunctionsDerived.cpp: -------------------------------------------------------------------------------- 1 | #include "FinalVirtualFunctionsDerived.h" 2 | 3 | FinalVirtualFunctionsDerived::FinalVirtualFunctionsDerived() 4 | { 5 | 6 | } 7 | 8 | FinalVirtualFunctionsBase::~FinalVirtualFunctionsBase(){ 9 | 10 | } 11 | void FinalVirtualFunctionsDerived::overridingFunc(){ 12 | std::cout<<"Derived Class Overriding Function 1"< 5 | #include 6 | #include 7 | #include "FinalVirtualFunctionsBase.h" 8 | #include "FinalVirtualFunctionsBase.cpp" 9 | //Author : Burak Dogancay 10 | /* We can also specify that a virtual function is pure virtual(abstract), by appending = 0 to the declaration.Classes with one or more pure virtual functions are 11 | considered to be abstract, and cannot be instantiated; only derived 12 | classes which define, or inherit definitions for, all pure virtual functions can be instantiated. 13 | 14 | *If we want to create a class that can't itself be instantiated, but doesn't prevent its derived classes from being 15 | instantiated, we can declare the destructor as pure virtual. Being the destructor, it must be defined anyways, 16 | if we want to be able to deallocate the instance. And as the destructor is most likely already virtual to prevent 17 | memory leaks during polymorphic use, we won't incur an unnecessary performance hit from declaring 18 | another function virtual. This can be useful when making interfaces. 19 | */ 20 | class FinalVirtualFunctionsDerived : public FinalVirtualFunctionsBase 21 | { 22 | public: 23 | FinalVirtualFunctionsDerived(); 24 | FinalVirtualFunctionsDerived(int val) = delete; 25 | FinalVirtualFunctionsDerived(FinalVirtualFunctionsDerived &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 26 | FinalVirtualFunctionsDerived(const FinalVirtualFunctionsDerived &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 27 | FinalVirtualFunctionsDerived &operator=(const FinalVirtualFunctionsDerived &ruleOfThree) = delete; // III. COPY ASSIGNMENT 28 | ~FinalVirtualFunctionsDerived() = default; 29 | 30 | virtual void overridingFunc() override; 31 | virtual void overridingFunc2() override; 32 | }; 33 | 34 | #endif -------------------------------------------------------------------------------- /19.MemberFunctions/main.cpp: -------------------------------------------------------------------------------- 1 | #include "VirtualMemberFunctions/FinalVirtualFunctionsDerived.h" 2 | #include "InlineFunctions/InlineFunctions.h" 3 | 4 | #include 5 | #include "VirtualMemberFunctions/FinalVirtualFunctionsDerived.cpp" 6 | #include "InlineFunctions/InlineFunctions.cpp" 7 | int main() 8 | { 9 | FinalVirtualFunctionsDerived funcDerived; 10 | InlineFunctions inlineFunctions; 11 | //Virtual Member Functions 12 | funcDerived.baseClassInformation(); 13 | funcDerived.overridingFunc(); 14 | funcDerived.overridingFunc2(); 15 | 16 | //Inline Functions 17 | inlineFunctions.nonMemberInlineFunc(5,20); 18 | } -------------------------------------------------------------------------------- /19.MemberFunctions/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/19.MemberFunctions/main.exe -------------------------------------------------------------------------------- /20.Namespaces/WhatisNameSpace/NamespaceExample.cpp: -------------------------------------------------------------------------------- 1 | #include "NameSpaceExample.h" 2 | 3 | NameBased::NameDerived::NameSpaceExample::NameSpaceExample() 4 | { 5 | 6 | } 7 | 8 | void NameBased::NameDerived::NameSpaceExample::printNamespace(){ 9 | std::cout<<"Namespace is working Well"< 4 | #include "WhatisNameSpace/NameSpaceExample.cpp" 5 | 6 | using namespace NameBased::NameDerived;// USİNG DİRECTİVE FOR NAMESPACES 7 | int main() 8 | { 9 | NameBased::NameDerived::NameSpaceExample nameSpaceExample; 10 | NameSpaceExample *nameSpaceExamplePtr = &nameSpaceExample; 11 | nameSpaceExample.printNamespace(); 12 | nameSpaceExamplePtr->printNamespace(); 13 | nameSpaceExamplePtr->printNamespace(); 14 | } -------------------------------------------------------------------------------- /20.Namespaces/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/20.Namespaces/main.exe -------------------------------------------------------------------------------- /21.STD-ARRAY/StdArray.h: -------------------------------------------------------------------------------- 1 | #ifndef STDARRAY_H 2 | #define STDARRAY_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | //Author : Burak Dogancay 9 | /* A function defined with the inline specifier is an inline function. An inline function can be multiply defined without 10 | violating the One Definition Rule, and can therefore be defined in a header with external linkage. Declaring a 11 | function inline hints to the compiler that the function should be inlined during code generation, but does not 12 | provide a guarantee. */ 13 | class StdArray 14 | { 15 | public: 16 | StdArray(); 17 | StdArray(int val) = delete; 18 | StdArray(StdArray &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 19 | StdArray(const StdArray &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 20 | StdArray &operator=(const StdArray &ruleOfThree) = delete; // III. COPY ASSIGNMENT 21 | ~StdArray() = default; 22 | 23 | void ArrayInitialization(); 24 | void ArrayInitStruct(); 25 | void ElementAccess(); 26 | void IteratingThroughArray(); 27 | void ChangingAllElements(); 28 | }; 29 | 30 | #endif -------------------------------------------------------------------------------- /21.STD-ARRAY/main.cpp: -------------------------------------------------------------------------------- 1 | #include "StdArray.h" 2 | #include 3 | 4 | int main() 5 | { 6 | StdArray stdArray; 7 | StdArray *newStdArray = new StdArray(); 8 | //stdArray.ArrayInitialization(); 9 | newStdArray->ArrayInitialization(); 10 | stdArray.ArrayInitStruct(); 11 | //stdArray.ElementAccess(); 12 | //stdArray.IteratingThroughArray(); 13 | //stdArray.ChangingAllElements(); 14 | } -------------------------------------------------------------------------------- /21.STD-ARRAY/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/21.STD-ARRAY/main.exe -------------------------------------------------------------------------------- /22.STD-MAP/StdMap.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/22.STD-MAP/StdMap.exe -------------------------------------------------------------------------------- /22.STD-MAP/StdMap.h: -------------------------------------------------------------------------------- 1 | #ifndef STDMAP_H 2 | #define STDMAP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | //Author : Burak Dogancay 10 | /* 11 | - To use any of std::map or std::multimap the header file should be included. 12 | - std::map and std::multimap both keep their elements sorted according to the ascending order of keys. In 13 | case of std::multimap, no sorting occurs for the values of the same key. 14 | - The basic difference between std::map and std::multimap is that the std::map one does not allow duplicate 15 | values for the same key where std::multimap does. 16 | - Maps are implemented as binary search trees. So search(), insert(), erase() takes Θ(log n) time in 17 | average. For constant time operation use std::unordered_map. 18 | - size() and empty() functions have Θ(1) time complexity, number of nodes is cached to avoid walking 19 | through tree each time these functions are called. */ 20 | class StdMap 21 | { 22 | public: 23 | StdMap(); 24 | StdMap(int val) = delete; 25 | StdMap(StdMap &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 26 | StdMap(const StdMap &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 27 | StdMap &operator=(const StdMap &ruleOfThree) = delete; // III. COPY ASSIGNMENT 28 | ~StdMap() = default; 29 | 30 | void mapAccessingElements(); 31 | void iteratorBaseAproach(); 32 | void insertingElements(); 33 | void initializingElments(); 34 | void deletingElemenets(); 35 | }; 36 | 37 | #endif -------------------------------------------------------------------------------- /22.STD-MAP/main.cpp: -------------------------------------------------------------------------------- 1 | #include "StdMap.h" 2 | #include 3 | 4 | int main() 5 | { 6 | StdMap stdMap; 7 | 8 | stdMap.mapAccessingElements(); 9 | stdMap.iteratorBaseAproach(); 10 | stdMap.insertingElements(); 11 | stdMap.deletingElemenets(); 12 | } -------------------------------------------------------------------------------- /22.STD-MAP/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/22.STD-MAP/main.exe -------------------------------------------------------------------------------- /23.STD-UNORDERED_MAP/UnorderedMap.cpp: -------------------------------------------------------------------------------- 1 | #include "UnorderedMap.h" 2 | UnorderedMap::UnorderedMap() 3 | { 4 | } 5 | 6 | void UnorderedMap::unorderedMapExample(){ 7 | std::unordered_map first; 8 | first["One"] = 1; 9 | first["two"] = 2; 10 | first["three"] = 3; 11 | 12 | std::pair bar = std::make_pair("Four", 4); //make a pair of same type 13 | first.insert(bar); //can also use insert to feed the values 14 | 15 | for (auto &mapVariable : first){ 16 | 17 | std::cout<<"Unordered Map Variables : "< 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | //Author : Burak Dogancay 13 | /* std::unordered_map is just an associative container. It works on keys and their maps. Key as the names goes, helps 14 | to have uniqueness in the map. While the mapped value is just a content that is associated with the key. The data 15 | types of this key and map can be any of the predefined data type or user-defined. 16 | 17 | Internally, the elements are not sorted in any particular order, but organized into buckets. Which bucket an element is placed into depends entirely on the hash of its key. 18 | Keys with the same hash code appear in the same bucket. 19 | This allows fast access to individual elements, since once the hash is computed, it refers to the exact bucket the element is placed into. 20 | */ 21 | class UnorderedMap 22 | { 23 | public: 24 | UnorderedMap(); 25 | UnorderedMap(int val) = delete; 26 | UnorderedMap(UnorderedMap &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 27 | UnorderedMap(const UnorderedMap &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 28 | UnorderedMap &operator=(const UnorderedMap &ruleOfThree) = delete; // III. COPY ASSIGNMENT 29 | ~UnorderedMap() = default; 30 | 31 | void unorderedMapExample(); 32 | }; 33 | 34 | #endif -------------------------------------------------------------------------------- /23.STD-UNORDERED_MAP/main.cpp: -------------------------------------------------------------------------------- 1 | #include "UnorderedMap.h" 2 | 3 | int main() 4 | { 5 | //Check for complex implementation 6 | UnorderedMap unorderedMap; 7 | unorderedMap.unorderedMapExample(); 8 | } -------------------------------------------------------------------------------- /23.STD-UNORDERED_MAP/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/23.STD-UNORDERED_MAP/main.exe -------------------------------------------------------------------------------- /24.STRUCTS/StructExample.cpp: -------------------------------------------------------------------------------- 1 | #include "StructExample.h" 2 | typedef StructExample::PackConcenationProcess StructExamplePack; 3 | StructExample::StructExample() 4 | { 5 | } 6 | 7 | void StructExample::myVariableProcess(){ 8 | MyVarStruct myVarStruct; 9 | int sumVars = 0; 10 | int extractVars = 0; 11 | 12 | sumVars = myVarStruct.myVariable1 + myVarStruct.myVariable2 + myVarStruct.myVariable3; 13 | extractVars = myVarStruct.myVariable1 - myVarStruct.myVariable2 - myVarStruct.myVariable3; 14 | 15 | std::cout<<"------ MY VARIABLE STRUCT EXAMPLE------"<mSrcPack.push_back(pDataPack); 26 | } 27 | this->concatToVecPacks(this->mSrcPack, this->mSrcPack.size()); 28 | } 29 | 30 | void StructExamplePack::concatToVecPacks(std::vector &pRawDataPack,int pPackSize) { 31 | 32 | if (!pRawDataPack.empty()) { 33 | this->clearPackage(this->mDstPack); 34 | for (char& tData : pRawDataPack) { 35 | this->mDstPack.push_back(tData); 36 | } 37 | 38 | this->concatToIntVar(); 39 | } 40 | } 41 | 42 | void StructExamplePack::concatToIntVar(){ 43 | 44 | for (char& tData : this->mDstPack) { 45 | this->concatVariable = ((concatVariable << 8) + tData) & 0xFFFF; 46 | 47 | } 48 | } 49 | 50 | void StructExamplePack::clearPackage(std::vector& pRawDataPack) { 51 | if (!pRawDataPack.empty()) { 52 | pRawDataPack.clear(); 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /24.STRUCTS/StructExample.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/24.STRUCTS/StructExample.exe -------------------------------------------------------------------------------- /24.STRUCTS/StructExample.h: -------------------------------------------------------------------------------- 1 | #ifndef STRUCTEXAMPLE_H 2 | #define STRUCTEXAMPLE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "StructBasePackages.h" 12 | //Author : Burak Dogancay 13 | 14 | class StructExample 15 | { 16 | public: 17 | StructExample(); 18 | StructExample(int val) = delete; 19 | StructExample(StructExample &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 20 | StructExample(const StructExample &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 21 | StructExample &operator=(const StructExample &ruleOfThree) = delete; // III. COPY ASSIGNMENT 22 | ~StructExample() = default; 23 | 24 | void myVariableProcess(); 25 | BaykarUavInfo baykarUavInfo; 26 | 27 | typedef struct PackConcenationProcess { 28 | PackConcenationProcess() { 29 | concatVariable = 0; 30 | } 31 | int concatVariable; 32 | std::vector mSrcPack; 33 | std::vector mDstPack; 34 | void addPackage(char pDataPack); 35 | void concatToVecPacks(std::vector &pRawDataPack,int pPackSize); 36 | void concatToIntVar(); 37 | void clearPackage(std::vector& pRawDataPack); 38 | }PackConcenationProcess; 39 | 40 | typedef struct{ 41 | int myVariable1 = 20; 42 | int myVariable2 = 30; 43 | int myVariable3 = 50; 44 | } MyVarStruct; 45 | 46 | 47 | }; 48 | 49 | #endif -------------------------------------------------------------------------------- /24.STRUCTS/main.cpp: -------------------------------------------------------------------------------- 1 | #include "StructExample.h" 2 | #include 3 | 4 | int main() 5 | { 6 | 7 | 8 | std::unique_ptr structExmp = std::make_unique(); 9 | 10 | structExmp.get()->myVariableProcess(); 11 | 12 | //PACK CONCATANATION 13 | StructExample::PackConcenationProcess tconcatVariables; 14 | char pack1 = 0x01; 15 | char pack2 = 0x04; 16 | tconcatVariables.clearPackage(tconcatVariables.mSrcPack); 17 | tconcatVariables.addPackage(pack1); 18 | tconcatVariables.addPackage(pack2); 19 | std::cout << "First Pack : " << std::bitset<8>(tconcatVariables.mDstPack[0])<< std::endl; 20 | std::cout << "Second Pack : " << std::bitset<8>(tconcatVariables.mDstPack[1])<< std::endl; 21 | std::cout << "Conatanated Variable : " << tconcatVariables.concatVariable<baykarUavInfo.name<baykarUavInfo.type<baykarUavInfo.company< 5 | #include 6 | #include 7 | //Author : Burak Dogancay 8 | 9 | class StdFunction 10 | { 11 | public: 12 | StdFunction(); 13 | StdFunction(int val) = delete; 14 | ~StdFunction() = default;// I DESTRUCTOR 15 | StdFunction(const StdFunction &ruleOfThree) = default; // II. COPY CONSTRUCTOR 16 | StdFunction(StdFunction &&ruleOfFive) noexcept; //III. MOVE CONSTRUCTOR 17 | StdFunction& operator=(const StdFunction &ruleOfThree) ; // IV COPY ASSIGNMENT 18 | StdFunction& operator=(StdFunction&& ruleOfFive) noexcept=default; // V. MOVE ASSIGNMENT 19 | 20 | 21 | void simpleFunction(int pI, const std::string& pString); 22 | void simpleCallIntFunct(const std::string& a); 23 | void simpleCallVoidFunct(); 24 | 25 | 26 | 27 | }; 28 | 29 | #endif -------------------------------------------------------------------------------- /25.STD-FUNCTION/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/25.STD-FUNCTION/main.exe -------------------------------------------------------------------------------- /26.STD-FORWARD_LIST-PAIR/StdForwardList.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/26.STD-FORWARD_LIST-PAIR/StdForwardList.exe -------------------------------------------------------------------------------- /26.STD-FORWARD_LIST-PAIR/main.cpp: -------------------------------------------------------------------------------- 1 | #include "StdForwardList.h" 2 | #include 3 | 4 | int main() 5 | { 6 | //Check for complex implementation 7 | StdForwardList stdForwardList; 8 | 9 | stdForwardList.forwardListInit(); 10 | stdForwardList.pairExample(); 11 | } -------------------------------------------------------------------------------- /26.STD-FORWARD_LIST-PAIR/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/26.STD-FORWARD_LIST-PAIR/main.exe -------------------------------------------------------------------------------- /27.STD-OPTIONAL/StdOptional.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/27.STD-OPTIONAL/StdOptional.exe -------------------------------------------------------------------------------- /27.STD-OPTIONAL/StdOptional.h: -------------------------------------------------------------------------------- 1 | #ifndef STDOPTIONAL_H 2 | #define STDOPTIONAL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | //Author : Burak Dogancay 9 | /* 10 | std::optional türünden bir nesne, programın çalışma zamanının belirli bir noktasında T türünden bir değer tutuyor ya da tutmuyor durumda olabilir. 11 | optional nesnesinin bir değere sahip olması kadar bir değere sahip olmaması da son derece doğal bir durum. Size bir bardak veriliyor. Bardak dolu da olabilir boş da. 12 | Diğer taraftan bir optional nesnesi tutacağı değer için kendisi için ayrılmış bir bellek alanınını kullanıyor. Yani dinamik bir bellek alanına ihtiyaç duymuyor. 13 | */ 14 | class StdOptional 15 | { 16 | public: 17 | StdOptional(); 18 | StdOptional(int val) = delete; 19 | StdOptional(StdOptional &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 20 | StdOptional(const StdOptional &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 21 | StdOptional &operator=(const StdOptional &ruleOfThree) = delete; // III. COPY ASSIGNMENT 22 | ~StdOptional() = default; 23 | 24 | struct UavBaseControl 25 | { 26 | std::string name; 27 | }; 28 | 29 | struct Uav{ 30 | std::string name; 31 | std::optional uavBaseControl; 32 | }; 33 | 34 | 35 | void optionalInitializing(); 36 | void stdOptionalProcess(); 37 | void stdOptionalStructExample(); 38 | std::optional stdOptionalReturnVal(); 39 | void stdOptionalValueOr(); 40 | 41 | }; 42 | 43 | #endif -------------------------------------------------------------------------------- /27.STD-OPTIONAL/main.cpp: -------------------------------------------------------------------------------- 1 | #include "StdOptional.h" 2 | #include 3 | 4 | int main() 5 | { 6 | StdOptional stdOptional; 7 | 8 | std::cout<<"Adress of the constructor : "<<&stdOptional<< std::endl; 9 | stdOptional.optionalInitializing(); 10 | stdOptional.stdOptionalProcess(); 11 | stdOptional.stdOptionalStructExample(); 12 | stdOptional.stdOptionalReturnVal(); 13 | stdOptional.stdOptionalValueOr(); 14 | 15 | } -------------------------------------------------------------------------------- /27.STD-OPTIONAL/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/27.STD-OPTIONAL/main.exe -------------------------------------------------------------------------------- /28.STD-VARIANT-ANY-SET-MULTISET/main.cpp: -------------------------------------------------------------------------------- 1 | #include "StdVariantAny.h" 2 | using VariantExample::StdVariant; 3 | using AnyExample::StdAny; 4 | using SetMultiSetExample::StdSetMultiset; 5 | int main() 6 | { 7 | //Check for complex implementation 8 | StdVariant stdVariant; 9 | StdAny stdAny; 10 | StdSetMultiset stdSetMultiset; 11 | 12 | stdVariant.variantBasicExample(); 13 | stdAny.anyBasicExample(); 14 | stdSetMultiset.setMultisetBasicExample(); 15 | stdSetMultiset.setMultisetOp(); 16 | 17 | 18 | } -------------------------------------------------------------------------------- /28.STD-VARIANT-ANY-SET-MULTISET/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/28.STD-VARIANT-ANY-SET-MULTISET/main.exe -------------------------------------------------------------------------------- /29.ENUMS/EnumExample.cpp: -------------------------------------------------------------------------------- 1 | #include "EnumExample.h" 2 | 3 | EnumExample::EnumExample() 4 | { 5 | } 6 | 7 | void EnumExample::enumClassProcess(int enumType){ 8 | 9 | std::cout<<"enum type is : "<< enumType< 5 | #include 6 | #include 7 | #include 8 | #include 9 | //Author : Burak Dogancay 10 | /* - Prefer enumerations over macros 11 | - Use enumerations to represent sets of related named constants 12 | - Prefer class enums over “plain” enums 13 | - Define operations on enumerations for safe and simple use 14 | - Avoid unnamed enumerations 15 | - Specify the underlying type of an enumeration only when necessary 16 | *The default is the easiest to read and write. int is the default integer type. int is compatible with C enums. 17 | - Specify enumerator values only when necessary 18 | */ 19 | class EnumExample 20 | { 21 | public: 22 | EnumExample(); 23 | EnumExample(int val) = delete; 24 | EnumExample(EnumExample &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 25 | EnumExample(const EnumExample &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 26 | EnumExample &operator=(const EnumExample &ruleOfThree) = delete; // III. COPY ASSIGNMENT 27 | ~EnumExample() = default; 28 | 29 | void enumClassProcess(int enumType); 30 | void iterator_over_enum(); 31 | 32 | //Scoped Enum 33 | enum class UavTypesClass 34 | { 35 | tb2, 36 | akinci, 37 | anka, 38 | aksungur 39 | }; 40 | 41 | //Use enumerations to represent sets of related named constants 42 | enum UavTypesNormal 43 | { 44 | tb2 = 0, 45 | akinci = 1, 46 | anka = 2, 47 | aksungur = 3 48 | }; 49 | 50 | UavTypesNormal &operator++(int en) 51 | { 52 | if (en == static_cast(UavTypesNormal::aksungur)) 53 | { 54 | throw std::out_of_range("for E& operator ++ (E&)"); 55 | } 56 | en = static_cast(UavTypesNormal(static_cast::type>(en) + 1)); 57 | return (UavTypesNormal&)en; 58 | } 59 | }; 60 | 61 | #endif -------------------------------------------------------------------------------- /29.ENUMS/main.cpp: -------------------------------------------------------------------------------- 1 | #include "EnumExample.h" 2 | #include 3 | 4 | int main() 5 | { 6 | EnumExample enumExample; 7 | 8 | EnumExample::UavTypesClass uav = EnumExample::UavTypesClass::akinci; 9 | enumExample.enumClassProcess(static_cast(uav));//if we dont use static cast we get conversion type error 10 | enumExample.enumClassProcess(static_cast(EnumExample::UavTypesClass::aksungur));//Alternative way of 11 | enumExample.enumClassProcess(EnumExample::UavTypesNormal::tb2);//compiler does not give any error as enum class type.Therefore you should use enum class to see type errors 12 | 13 | //enumExample.iterator_over_enum(); 14 | } -------------------------------------------------------------------------------- /29.ENUMS/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/29.ENUMS/main.exe -------------------------------------------------------------------------------- /30.IntegerSequence/IntegerSequence.cpp: -------------------------------------------------------------------------------- 1 | #include "IntegerSequence.h" 2 | IntegerSequence::IntegerSequence() 3 | { 4 | } 5 | 6 | void IntegerSequence::func(int i, std::string const &s) 7 | { 8 | std::cout << "f(" << i << ", " << s << ")\n"; 9 | } 10 | 11 | void IntegerSequence::func(int i, double d, std::string const &s) 12 | { 13 | std::cout << "f(" << i << ", " << d << ", " << s << ")\n"; 14 | } 15 | 16 | void IntegerSequence::func(char c, int i, double d, std::string const &s) 17 | { 18 | std::cout << "f(" << c << ", " << i << ", " << d << ", " << s << ")\n"; 19 | } 20 | 21 | void IntegerSequence::func(int i, int j, int k) 22 | { 23 | std::cout << "f(" << i << ", " << j << ", " << k << ")\n"; 24 | } 25 | 26 | template 27 | void IntegerSequence::processSub(Tuple const &tuple, std::index_sequence) 28 | { 29 | func(std::get(tuple)...); 30 | } 31 | 32 | template 33 | void IntegerSequence::process(Tuple const &tuple) 34 | { 35 | processSub(tuple, std::make_index_sequence::value>()); 36 | } -------------------------------------------------------------------------------- /30.IntegerSequence/IntegerSequence.h: -------------------------------------------------------------------------------- 1 | #ifndef INTEGERSEQUENCE_H 2 | #define INTEGERSEQUENCE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | //Author : Burak Dogancay 12 | 13 | class IntegerSequence 14 | { 15 | public: 16 | IntegerSequence(); 17 | IntegerSequence(int val) = delete; 18 | IntegerSequence(IntegerSequence &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 19 | IntegerSequence(const IntegerSequence &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 20 | IntegerSequence &operator=(const IntegerSequence &ruleOfThree) = delete; // III. COPY ASSIGNMENT 21 | ~IntegerSequence() = default; 22 | 23 | void func(int i, std::string const& s); 24 | void func(int i, double d, std::string const& s); 25 | void func(char c, int i, double d, std::string const& s); 26 | void func(int i, int j, int k); 27 | 28 | template 29 | void processSub(Tuple const& tuple, std::index_sequence); 30 | 31 | template 32 | void process(Tuple const& tuple); 33 | 34 | 35 | }; 36 | 37 | #endif -------------------------------------------------------------------------------- /30.IntegerSequence/main.cpp: -------------------------------------------------------------------------------- 1 | #include "IntegerSequence.h" 2 | 3 | int main() 4 | { 5 | //Check for complex implementation 6 | IntegerSequence integerSequence; 7 | integerSequence.process(std::make_tuple(1, 3.14, std::string("foo"))); 8 | } -------------------------------------------------------------------------------- /31.Inline Varibales/InlineVariables.cpp: -------------------------------------------------------------------------------- 1 | #include "InlineVariables.h" 2 | InlineVariables::InlineVariables() 3 | { 4 | } 5 | 6 | void InlineVariables::inlineVarExample(){ 7 | std::cout<<"Inline Variable Before Change : "< 5 | //Author : Burak Dogancay 6 | 7 | /* A static data member of the class may be fully defined within the class definition if it is declared inline. For 8 | example, the following class may be defined in a header. Prior to C++17, it would have been necessary to provide a 9 | .cpp file to contain the definition of Foo::num_instances so that it would be defined only once, but in C++17 the 10 | multiple definitions of the inline variable Foo::num_instances all refer to the same int object. 11 | */ 12 | class InlineVariables 13 | { 14 | public: 15 | InlineVariables(); 16 | InlineVariables(int val) = delete; 17 | InlineVariables(InlineVariables &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 18 | InlineVariables(const InlineVariables &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 19 | InlineVariables &operator=(const InlineVariables &ruleOfThree) = delete; // III. COPY ASSIGNMENT 20 | ~InlineVariables() = default; 21 | inline static int inlinevar = 0; 22 | inline static int inlinevar2 = 10; 23 | 24 | //As a special case, a constexpr static data member is implicitly inline 25 | static constexpr int constExp = 0; 26 | static constexpr int constExp2 = 10; 27 | 28 | void inlineVarExample(); 29 | void constantExpExample(); 30 | }; 31 | 32 | #endif -------------------------------------------------------------------------------- /31.Inline Varibales/main.cpp: -------------------------------------------------------------------------------- 1 | #include "InlineVariables.h" 2 | 3 | int main() 4 | { 5 | //Check for complex implementation 6 | InlineVariables inlineVariables; 7 | 8 | inlineVariables.inlineVarExample(); 9 | inlineVariables.constantExpExample(); 10 | } -------------------------------------------------------------------------------- /31.Inline Varibales/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/31.Inline Varibales/main.exe -------------------------------------------------------------------------------- /32.Chrono(Time Measurement)/TimeMeasurement.cpp: -------------------------------------------------------------------------------- 1 | #include "TimeMeasurement.h" 2 | 3 | TimeMeasurement::TimeMeasurement() 4 | { 5 | } 6 | 7 | void TimeMeasurement::elapsedTimeExample() 8 | { 9 | auto tStartTime = std::chrono::system_clock::now(); 10 | int i = 0; 11 | while (i <= 20000) 12 | { 13 | i++; 14 | std::cout << i << std::endl; 15 | } 16 | auto tEndTime = std::chrono::system_clock::now(); 17 | std::chrono::duration elapsed = tEndTime - tStartTime; 18 | std::cout << "Elapsed time: " << elapsed.count() <>::type> days; 41 | 42 | // Create start time span 43 | std::tm tm_start = createTmStruct(year, 1, 1, 0, 0, 0); 44 | auto tms = system_clock::from_time_t(std::mktime(&tm_start)); 45 | 46 | // Create end time span 47 | std::tm tm_end = createTmStruct(year + 1, 1, 1, 0, 0, 0); 48 | auto tme = system_clock::from_time_t(std::mktime(&tm_end)); 49 | 50 | // Calculate time duration between those two dates 51 | auto diff_in_days = std::chrono::duration_cast(tme - tms); 52 | 53 | return diff_in_days.count(); 54 | } 55 | -------------------------------------------------------------------------------- /32.Chrono(Time Measurement)/TimeMeasurement.h: -------------------------------------------------------------------------------- 1 | #ifndef TIMEMEASUREMENT_H 2 | #define TIMEMEASUREMENT_H 3 | 4 | #include 5 | #include 6 | //Author : Burak Dogancay 7 | /* A static data member of the class may be fully defined within the class definition if it is declared inline. For 8 | example, the following class may be defined in a header. Prior to C++17, it would have been necessary to provide a 9 | .cpp file to contain the definition of Foo::num_instances so that it would be defined only once, but in C++17 the 10 | multiple definitions of the inline variable Foo::num_instances all refer to the same int object. 11 | */ 12 | class TimeMeasurement 13 | { 14 | public: 15 | TimeMeasurement(); 16 | TimeMeasurement(int val) = delete; 17 | TimeMeasurement(TimeMeasurement &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 18 | TimeMeasurement(const TimeMeasurement &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 19 | TimeMeasurement &operator=(const TimeMeasurement &ruleOfThree) = delete; // III. COPY ASSIGNMENT 20 | ~TimeMeasurement() = default; //Destructor 21 | 22 | void elapsedTimeExample(); 23 | std::tm createTmStruct(int year, int month, int day, int hour, int minutes, int seconds); 24 | int get_days_in_year(int year); 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /32.Chrono(Time Measurement)/main.cpp: -------------------------------------------------------------------------------- 1 | #include "TimeMeasurement.h" 2 | 3 | int main() 4 | { 5 | //Check for complex implementation 6 | TimeMeasurement timeMeasurement; 7 | timeMeasurement.elapsedTimeExample(); 8 | 9 | for (int year = 2000; year <= 2016; ++year) 10 | { 11 | std::cout << "There are " << timeMeasurement.get_days_in_year(year) << " days in " << year << "\n"; 12 | } 13 | } -------------------------------------------------------------------------------- /32.Chrono(Time Measurement)/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/32.Chrono(Time Measurement)/main.exe -------------------------------------------------------------------------------- /33.Exceptions-TryCatch/Exceptions.cpp: -------------------------------------------------------------------------------- 1 | #include "Exceptions.h" 2 | 3 | Exceptions::Exceptions() 4 | { 5 | } 6 | 7 | void Exceptions::catching_Exception() 8 | { 9 | std::string tString = {"String"}; 10 | 11 | try 12 | { 13 | tString.at(10); 14 | } 15 | catch (const std::out_of_range &e) 16 | { 17 | // what() is inherited from std::exception and contains an explanatory message 18 | std::cout << e.what(); 19 | } 20 | } 21 | void Exceptions::multipleCatch() 22 | { 23 | std::string tString("string"); 24 | 25 | try 26 | { 27 | tString.reserve(2); // reserve extra capacity, may throw std::length_error 28 | tString.at(10); // access element, may throw std::out_of_range 29 | } 30 | catch (const std::length_error &e) 31 | { 32 | std::cout << e.what() << std::endl; 33 | } 34 | catch (const std::out_of_range &e) 35 | { 36 | std::cout << e.what() << std::endl; 37 | } 38 | } 39 | 40 | void Exceptions::generalExceptions() 41 | { 42 | 43 | std::string tString("string"); 44 | 45 | try 46 | { 47 | tString.reserve(2); // reserve extra capacity, may throw std::length_error 48 | tString.at(10); // access element, may throw std::out_of_range 49 | } 50 | catch (const std::exception &e) 51 | { 52 | std::cout << e.what() << std::endl; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /33.Exceptions-TryCatch/Exceptions.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/33.Exceptions-TryCatch/Exceptions.exe -------------------------------------------------------------------------------- /33.Exceptions-TryCatch/Exceptions.h: -------------------------------------------------------------------------------- 1 | #ifndef EXCEPTIONS_H 2 | #define EXCEPTIONS_H 3 | 4 | #include 5 | #include 6 | //Author : Burak Dogancay 7 | /* 8 | A try/catch block is used to catch exceptions. The code in the try section is the code that may throw an exception, 9 | and the code in the catch clause(s) handles the exception. 10 | Check Exceptions detaily 11 | */ 12 | class Exceptions 13 | { 14 | public: 15 | Exceptions(); 16 | Exceptions(int val) = delete; 17 | Exceptions(Exceptions &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 18 | Exceptions(const Exceptions &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 19 | Exceptions &operator=(const Exceptions &ruleOfThree) = delete; // III. COPY ASSIGNMENT 20 | ~Exceptions() = default; //Destructor 21 | 22 | void catching_Exception(); 23 | void multipleCatch(); 24 | void generalExceptions(); 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /33.Exceptions-TryCatch/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Exceptions.h" 2 | 3 | 4 | int main() 5 | { 6 | //Check for complex implementation 7 | Exceptions exceptions; 8 | //exceptions.catching_Exception(); 9 | //exceptions.multipleCatch(); 10 | exceptions.generalExceptions(); 11 | 12 | } -------------------------------------------------------------------------------- /33.Exceptions-TryCatch/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/33.Exceptions-TryCatch/main.exe -------------------------------------------------------------------------------- /34.LAMBDAS/Lambdas.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/34.LAMBDAS/Lambdas.exe -------------------------------------------------------------------------------- /34.LAMBDAS/Lambdas.h: -------------------------------------------------------------------------------- 1 | #ifndef LAMBDAS_H 2 | #define LAMBDAS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | //Author : Burak Dogancay 9 | /* 10 | A lambda expression provides a concise way to create simple function objects. A lambda expression is a prvalue 11 | whose result object is called closure object, which behaves like a function object 12 | In such cases, lambda 13 | expressions are generally preferred because they allow defining the function objects inline 14 | */ 15 | class Lambdas 16 | { 17 | public: 18 | Lambdas(); 19 | Lambdas(int val) = delete; 20 | Lambdas(Lambdas &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 21 | Lambdas(const Lambdas &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 22 | Lambdas &operator=(const Lambdas &ruleOfThree) = delete; // III. COPY ASSIGNMENT 23 | ~Lambdas() = default; //Destructor 24 | 25 | struct LambdaStruct{ 26 | LambdaStruct(){ 27 | lambdaVariable = 0; 28 | } 29 | int lambdaVariable; 30 | }lambdaStruct; 31 | 32 | void lambdaDef(int i); 33 | void lambdaDef2(int i); 34 | void captureList(); 35 | void parameterList(); 36 | void callingLambda(); 37 | void specifiyingReturnType(); 38 | void captureByValue(); 39 | void captureByValueSecond(); 40 | void recursiveLambdas(); 41 | void defaultCapture(); 42 | void classLambdaEx(); 43 | void captureByReference(); 44 | void genericLambdas(); 45 | void generilizedCapture(); 46 | 47 | 48 | 49 | }; 50 | 51 | #endif -------------------------------------------------------------------------------- /34.LAMBDAS/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Lambdas.h" 2 | 3 | 4 | int main() 5 | { 6 | //Check for complex implementation 7 | Lambdas lambdaClass; 8 | 9 | lambdaClass.callingLambda(); 10 | lambdaClass.specifiyingReturnType(); 11 | lambdaClass.captureByValue(); 12 | lambdaClass.captureByValueSecond(); 13 | lambdaClass.recursiveLambdas(); 14 | lambdaClass.classLambdaEx(); 15 | lambdaClass.captureByReference(); 16 | lambdaClass.genericLambdas(); 17 | lambdaClass.generilizedCapture(); 18 | } -------------------------------------------------------------------------------- /34.LAMBDAS/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/34.LAMBDAS/main.exe -------------------------------------------------------------------------------- /35.ValueCategories/ValueCategories.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/35.ValueCategories/ValueCategories.exe -------------------------------------------------------------------------------- /35.ValueCategories/ValueCategories.h: -------------------------------------------------------------------------------- 1 | #ifndef VALUECATEGORIES_H 2 | #define VALUECATEGORIES_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | //Author : Burak Dogancay 9 | 10 | class ValueCategories 11 | { 12 | public: 13 | ValueCategories(); 14 | ValueCategories(int val) = delete; 15 | ValueCategories(ValueCategories &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 16 | ValueCategories(const ValueCategories &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 17 | ValueCategories &operator=(const ValueCategories &ruleOfThree) = delete; // III. COPY ASSIGNMENT 18 | ~ValueCategories() = default; //Destructor 19 | 20 | /* An rvalue expression is any expression which can be implicitly moved from, regardless of whether it has identity. 21 | More precisely, rvalue expressions may be used as the argument to a function that takes a parameter of type T && 22 | (where T is the type of expr). Only rvalue expressions may be given as arguments to such function parameters; if a 23 | non-rvalue expression is used, then overload resolution will pick any function that does not use an rvalue reference 24 | parameter. And if none exist, then you get an error. */ 25 | 26 | void rValueExamples(); 27 | void xValueExample(); 28 | void prValueExample(); 29 | void lValueExample(); 30 | void glValueExample(); 31 | 32 | }; 33 | 34 | #endif -------------------------------------------------------------------------------- /35.ValueCategories/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ValueCategories.h" 2 | 3 | 4 | int main() 5 | { 6 | //Check for complex implementation 7 | ValueCategories valueCategoriesClass; 8 | //std::cout<<"Refrence var"; 9 | 10 | } -------------------------------------------------------------------------------- /35.ValueCategories/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/35.ValueCategories/main.exe -------------------------------------------------------------------------------- /36.Preprocessors/ConditionalLogic.cpp: -------------------------------------------------------------------------------- 1 | #include "ConditionalLogic.h" 2 | 3 | ConditionalLogic::ConditionalLogic() 4 | { 5 | } 6 | 7 | bool ConditionalLogic::printVariable(int var) 8 | { 9 | if (var) 10 | { 11 | std::cout << "Integer variable value : " << var << std::endl; 12 | return true; 13 | } 14 | else 15 | { 16 | return false; 17 | } 18 | } 19 | 20 | bool ConditionalLogic::removeFileDirectly(const std::string &path) 21 | { 22 | return remove(path.c_str()); 23 | } -------------------------------------------------------------------------------- /36.Preprocessors/ConditionalLogic.h: -------------------------------------------------------------------------------- 1 | #ifndef CONDITIONALLOGIC_H 2 | #define CONDITIONALLOGIC_H 3 | #define IOSTREAM 4 | #define WIN32 5 | //Author : Burak Dogancay 6 | /* In a nutshell, conditional pre-processing logic is about making code-logic available or unavailable for compilation 7 | using macro definitions. 8 | Three prominent use-cases are: 9 | different app profiles (e.g. debug, release, testing, optimised) that can be candidates of the same app (e.g. 10 | with extra logging). 11 | cross-platform compiles - single code-base, multiple compilation platforms. 12 | utilising a common code-base for multiple application versions (e.g. Basic, Premium and Pro versions of a 13 | software) - with slightly different features. */ 14 | #ifdef IOSTREAM 15 | #include 16 | #else 17 | #include 18 | #endif 19 | //or 20 | /* #ifndef IOSTREAM 21 | #include 22 | #endif */ 23 | 24 | #ifdef WIN32 25 | #include 26 | #include 27 | #endif 28 | 29 | 30 | 31 | 32 | class ConditionalLogic 33 | { 34 | public: 35 | ConditionalLogic(); 36 | ConditionalLogic(int val) = delete; 37 | ConditionalLogic(ConditionalLogic &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 38 | ConditionalLogic(const ConditionalLogic &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 39 | ConditionalLogic &operator=(const ConditionalLogic &ruleOfThree) = delete; // III. COPY ASSIGNMENT 40 | ~ConditionalLogic() = default; //Destructor 41 | 42 | bool printVariable(int var); 43 | bool removeFileDirectly(const std::string &path); 44 | }; 45 | 46 | #endif -------------------------------------------------------------------------------- /36.Preprocessors/IncludeGuards.cpp: -------------------------------------------------------------------------------- 1 | #include "IncludeGuards.h" 2 | 3 | IncludeGuards::IncludeGuards() 4 | { 5 | } 6 | 7 | void IncludeGuards::checkIncludeGuards(){ 8 | 9 | std::cout<<"Include Guards Class is created correctly"< 17 | #include 18 | #include 19 | #include 20 | 21 | /* The C preprocessor is a simple text parser/replacer that is run before the actual compilation of the code. Used to 22 | extend and ease the use of the C (and later C++) language, it can be used for: */ 23 | 24 | /* a. Including other files using #include 25 | b. Define a text-replacement macro using #define 26 | c. Conditional Compilation using#if #ifdef 27 | d. Platform/Compiler specific logic (as an extension of conditional compilation) */ 28 | 29 | class IncludeGuards 30 | { 31 | public: 32 | IncludeGuards(); 33 | IncludeGuards(int val) = delete; 34 | IncludeGuards(IncludeGuards &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 35 | IncludeGuards(const IncludeGuards &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 36 | IncludeGuards &operator=(const IncludeGuards &ruleOfThree) = delete; // III. COPY ASSIGNMENT 37 | ~IncludeGuards() = default; //Destructor 38 | 39 | void checkIncludeGuards(); 40 | }; 41 | 42 | #endif -------------------------------------------------------------------------------- /36.Preprocessors/Macros.h: -------------------------------------------------------------------------------- 1 | #ifndef MACROS_H 2 | #define MACROS_H 3 | #include 4 | #include "IncludeGuards.h" 5 | #define GuardClass mGuards 6 | //Author : Burak Dogancay 7 | /* Macros are categorized into two main groups: object-like macros and function-like macros. Macros are treated as a 8 | token substitution early in the compilation process */ 9 | class Macros 10 | { 11 | public: 12 | Macros(); 13 | Macros(int val) = delete; 14 | Macros(Macros &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 15 | Macros(const Macros &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 16 | Macros &operator=(const Macros &ruleOfThree) = delete; // III. COPY ASSIGNMENT 17 | ~Macros() = default; //Destructor 18 | 19 | void macroFuncExample(); 20 | void macroFuncSecondEx(); 21 | void complexFunctionMacros(); 22 | void moreComplexFunctionMacro(); 23 | void variadicFunctionMacro(); 24 | void preprocessorOperatorsFirstEx(); 25 | void preprocessorOperatorSecondEX(); 26 | void preprocessorOpVarDefine(); 27 | void preprocessorErrorMessage(); 28 | void variableMacro(); 29 | 30 | 31 | private: 32 | std::unique_ptr mGuards; 33 | }; 34 | 35 | #endif -------------------------------------------------------------------------------- /36.Preprocessors/main.cpp: -------------------------------------------------------------------------------- 1 | #include "IncludeGuards.h" 2 | #include "IncludeGuards.h" 3 | #include "ConditionalLogic.h" 4 | #include "UsefulMacros.h" 5 | #include "Macros.h" 6 | 7 | 8 | int main() 9 | { 10 | //Check for complex implementation 11 | IncludeGuards includeGuardClass; 12 | ConditionalLogic condLogicClass; 13 | Macros macros; 14 | 15 | includeGuardClass.checkIncludeGuards(); 16 | 17 | if (condLogicClass.printVariable(25)) 18 | std::cout<<"Function is working correctly"< 3 | Templates::Templates() : mNumber(0) 4 | { 5 | } 6 | 7 | template 8 | void Templates::setNum(T pNumber) 9 | { 10 | mNumber = pNumber; 11 | } 12 | 13 | template 14 | T Templates::plus1() const 15 | { 16 | return mNumber + 1; 17 | } 18 | template 19 | template 20 | void Templates::printSum(Type add1, Type add2) 21 | { 22 | std::cout << (add1 + add2) << std::endl; 23 | } -------------------------------------------------------------------------------- /37.Templates/Templates.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/37.Templates/Templates.exe -------------------------------------------------------------------------------- /37.Templates/TemplatesAnother.cpp: -------------------------------------------------------------------------------- 1 | #include "Templates.h" 2 | TemplatesAnother::TemplatesAnother(){ 3 | 4 | } -------------------------------------------------------------------------------- /37.Templates/TemplatesAnother.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/37.Templates/TemplatesAnother.exe -------------------------------------------------------------------------------- /37.Templates/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/37.Templates/main.exe -------------------------------------------------------------------------------- /38.ExplicitTypeConversion(CASTING)/Casting.h: -------------------------------------------------------------------------------- 1 | #ifndef CASTING_H 2 | #define CASTING_H 3 | #include 4 | #include "math.h" 5 | //Author : Burak Dogancay 6 | class Casting 7 | { 8 | public: 9 | Casting(); 10 | Casting(int val) = delete; 11 | Casting(Casting &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 12 | Casting(const Casting &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 13 | Casting &operator=(const Casting &ruleOfThree) = delete; // III. COPY ASSIGNMENT 14 | ~Casting() = default; //Destructor 15 | 16 | void constCastEx(); 17 | void staticCastEx(); 18 | void dynamicCastEx(); 19 | void reinterpretCastEx(); 20 | void enumConversion(); 21 | void voidPointertoTpointer(); 22 | 23 | }; 24 | #endif -------------------------------------------------------------------------------- /38.ExplicitTypeConversion(CASTING)/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Casting.h" 2 | #include 3 | 4 | int main() 5 | { 6 | /* reinterpret_cast is a low-level casting operator that should be used with extreme caution. 7 | It is typically used for situations where you have a deep understanding of memory layout and need to perform unsafe conversions. 8 | 9 | static_cast is a safe and well-defined casting operator suitable for most type conversions within C++'s type system. 10 | 11 | dynamic_cast is used in the context of inheritance and polymorphism to safely cast pointers or references to base and derived classes, 12 | performing runtime type checks to ensure validity. */ 13 | 14 | Casting tCasting; 15 | 16 | tCasting.constCastEx(); 17 | tCasting.staticCastEx(); 18 | //tCasting.dynamicCastEx(); 19 | //tCasting.reinterpretCastEx(); 20 | //tCasting.enumConversion(); 21 | //tCasting.voidPointertoTpointer(); 22 | 23 | } -------------------------------------------------------------------------------- /39.TypeInference-Auto/TypeInference.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/39.TypeInference-Auto/TypeInference.exe -------------------------------------------------------------------------------- /39.TypeInference-Auto/TypeInference.h: -------------------------------------------------------------------------------- 1 | #ifndef TYPEINFERENCE_H 2 | #define TYPEINFERENCE_H 3 | #include 4 | #include 5 | #include 6 | 7 | //Author : Burak Dogancay 8 | 9 | 10 | class TypeInference 11 | { 12 | public: 13 | TypeInference(); 14 | 15 | void autoDataType(); 16 | void autoLambda(); 17 | void autoLoops(); 18 | 19 | 20 | 21 | }; 22 | #endif -------------------------------------------------------------------------------- /39.TypeInference-Auto/main.cpp: -------------------------------------------------------------------------------- 1 | #include "TypeInference.h" 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | std::unique_ptr typeInference= std::make_unique(); 8 | 9 | //Call Auto Datatype 10 | typeInference.get()->autoDataType(); 11 | typeInference.get()->autoLambda(); 12 | } -------------------------------------------------------------------------------- /39.TypeInference-Auto/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/39.TypeInference-Auto/main.exe -------------------------------------------------------------------------------- /40.TypeTraits/TypeTraits.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/40.TypeTraits/TypeTraits.exe -------------------------------------------------------------------------------- /40.TypeTraits/TypeTraits.h: -------------------------------------------------------------------------------- 1 | //Author : Burak Dogancay 2 | #ifndef TYPETRAITS_H 3 | #define TYPETRAITS_H 4 | #include 5 | #include 6 | 7 | /* SFINAE 8 | C++ C++ language Templates 9 | "Substitution Failure Is Not An Error" 10 | 11 | This rule applies during overload resolution of function templates: 12 | When substituting the explicitly specified or deduced type for the template parameter fails, 13 | the specialization is discarded from the overload set instead of causing a compile error. 14 | This feature is used in template metaprogramming. */ 15 | class TypeTraits 16 | { 17 | public: 18 | TypeTraits(); 19 | TypeTraits(int val) = delete; 20 | TypeTraits(TypeTraits &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 21 | TypeTraits(const TypeTraits &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 22 | TypeTraits &operator=(const TypeTraits &ruleOfThree) = delete; // III. COPY ASSIGNMENT 23 | ~TypeTraits() = default; //Destructor 24 | 25 | //TYPE PROPERTIES 26 | void isContstant(); 27 | void isVolatile(); 28 | void isSigned(); 29 | void isUnsigned(); 30 | 31 | //STANDARD TYPE TRAITS 32 | void staticAssert(); 33 | void enableif(); 34 | void isPointer(); 35 | 36 | //TYPE RELATION 37 | void is_same(); 38 | void is_same_Alternative(); 39 | 40 | //CLASSIC TYPE TRAITS 41 | void isIntegral(); 42 | void isFloatingPoint(); 43 | void isEnum(); 44 | void isPointerEx(); 45 | void isClass(); 46 | 47 | }; 48 | #endif -------------------------------------------------------------------------------- /40.TypeTraits/main.cpp: -------------------------------------------------------------------------------- 1 | #include "TypeTraits.h" 2 | #include 3 | 4 | int main() 5 | { 6 | TypeTraits *typeTraits = new TypeTraits(); 7 | 8 | typeTraits->isContstant(); 9 | typeTraits->isSigned(); 10 | typeTraits->isUnsigned(); 11 | typeTraits->isVolatile(); 12 | 13 | //Standard tyeptraits 14 | typeTraits->isPointer(); 15 | 16 | //Type Relation 17 | typeTraits->is_same(); 18 | typeTraits->is_same_Alternative(); 19 | 20 | //Classic Type Traits 21 | typeTraits->isIntegral(); 22 | typeTraits->isFloatingPoint(); 23 | typeTraits->isEnum(); 24 | 25 | } -------------------------------------------------------------------------------- /40.TypeTraits/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/40.TypeTraits/main.exe -------------------------------------------------------------------------------- /41.TypedefAndAlias/TypedefAndAlias.h: -------------------------------------------------------------------------------- 1 | //Author : Burak Dogancay 2 | #ifndef TYPEDEFANDALIAS_H 3 | #define TYPEDEFANDALIAS_H 4 | #include 5 | #include 6 | #include 7 | 8 | class TypedefAndAlias 9 | { 10 | public: 11 | TypedefAndAlias(); 12 | 13 | void basicTypeDef(); 14 | void complexTypeDef(); 15 | void declareMultipleTypes(); 16 | void aliasDeclWithUsing(); 17 | 18 | 19 | 20 | 21 | 22 | }; 23 | #endif -------------------------------------------------------------------------------- /41.TypedefAndAlias/main.cpp: -------------------------------------------------------------------------------- 1 | //Author : Burak Dogancay 2 | #include "TypedefAndAlias.h" 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | std::unique_ptr typeDef= std::make_unique(); 9 | 10 | //Call Typedefand Alias Functions 11 | typeDef.get()->basicTypeDef(); 12 | typeDef.get()->declareMultipleTypes(); 13 | typeDef.get()->aliasDeclWithUsing(); 14 | 15 | } -------------------------------------------------------------------------------- /41.TypedefAndAlias/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/41.TypedefAndAlias/main.exe -------------------------------------------------------------------------------- /42.TypeDeduction/TypeDeduction.h: -------------------------------------------------------------------------------- 1 | //Author : Burak Dogancay 2 | #ifndef TYPEDEDUCTION_H 3 | #define TYPEDEDUCTION_H 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | 10 | 11 | class TypeDeduction 12 | { 13 | public: 14 | TypeDeduction(); 15 | 16 | void autoTypeDeduction(); 17 | void dclTypeAuto(); 18 | void anotherAutoTypeDedeuction(); 19 | 20 | 21 | //Template parameter deduction for constructors 22 | /* template 23 | vector(Iter, Iter) -> vector::value_type> 24 | 25 | int array[] = {1, 2, 3}; 26 | std::vector v(std::begin(array), std::end(array)); // deduces std::vector */ 27 | 28 | //Template Type Deduction 29 | template 30 | void f(T& param); //param is a reference 31 | void templateTypeDeduction(); 32 | 33 | 34 | 35 | }; 36 | #endif -------------------------------------------------------------------------------- /42.TypeDeduction/main.cpp: -------------------------------------------------------------------------------- 1 | //Author : Burak Dogancay 2 | #include "TypeDeduction.h" 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | std::unique_ptr typeDeduct= std::make_unique(); 9 | 10 | //Call Typedefand Alias Functions 11 | typeDeduct.get()->autoTypeDeduction(); 12 | typeDeduct.get()->dclTypeAuto(); 13 | typeDeduct.get()->anotherAutoTypeDedeuction(); 14 | typeDeduct.get()->templateTypeDeduction(); 15 | 16 | } -------------------------------------------------------------------------------- /42.TypeDeduction/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/42.TypeDeduction/main.exe -------------------------------------------------------------------------------- /43-Alignment/Alignment.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/43-Alignment/Alignment.exe -------------------------------------------------------------------------------- /43-Alignment/Alignment.h: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #ifndef ALIGNMENT_H 3 | #define ALIGNMENT_H 4 | #include 5 | #include 6 | //All types in C++ have an alignment. This is a restriction on the memory address that objects of that type can be 7 | //created within. A memory address is valid for an object's creation if dividing that address by the object's alignment 8 | //is a whole number. 9 | class Alignment 10 | { 11 | public: 12 | Alignment(); 13 | void alignmentControl(); 14 | void checkAlignment(); 15 | }; 16 | 17 | #endif -------------------------------------------------------------------------------- /43-Alignment/main.cpp: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #include "Alignment.h" 3 | 4 | 5 | int main() 6 | { 7 | std::unique_ptr alignmentClass = std::make_unique(); 8 | 9 | alignmentClass.get()->alignmentControl(); 10 | alignmentClass.get()->checkAlignment(); 11 | } -------------------------------------------------------------------------------- /43-Alignment/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/43-Alignment/main.exe -------------------------------------------------------------------------------- /44-UndefinedBehaviour/UndefinedBehaviour.h: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #ifndef UNDEFINEDBEHAVIOUR_H 3 | #define UNDEFINEDBEHAVIOUR_H 4 | #include 5 | #include 6 | 7 | //Undefined behaviour means that when a program encounters UB, it is allowed to do whatever it wants. This often means a crash, 8 | //but it may simply do nothing, make demons fly out of your nose, or even appear to work properly! 9 | class UndefinedBehaviour 10 | { 11 | public: 12 | UndefinedBehaviour(); 13 | void readingOrWritingnullPointer(); 14 | void unInitVariable(); 15 | void accessOutOfBoundsIndex(); 16 | void noVirtualDestructorDerivedObject(); 17 | void invalidPointerArithmetic(); 18 | int nonreturnTypeUB(); 19 | 20 | int &getX(); 21 | void accessDanglingReference(); 22 | 23 | void intDivisionByZero(); 24 | void shiftingInvalidNumber(); 25 | void incorrectPairingMemAlloc(); 26 | void signedIntegerOverflow(); 27 | void modifyConstObj(); 28 | void returnFromFunction(); 29 | void infTemplateRecursion(); 30 | void overflowDuringConv(); 31 | void modifyingStringLiteral(); 32 | void accessWrongTypeObj(); 33 | void destroyDestroyedObj(); 34 | void floatingPointOverflow(); 35 | void funCallMismatchPointerType(); 36 | }; 37 | 38 | #endif -------------------------------------------------------------------------------- /44-UndefinedBehaviour/main.cpp: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #include "UndefinedBehaviour.h" 3 | 4 | 5 | int main() 6 | { 7 | std::unique_ptr undefBehaviourClass = std::make_unique(); 8 | 9 | //undefBehaviourClass.get()->readingOrWritingnullPointer(); 10 | //undefBehaviourClass.get()->unInitVariable(); 11 | //undefBehaviourClass.get()->accessOutOfBoundsIndex(); 12 | //undefBehaviourClass.get()->invalidPointerArithmetic(); 13 | //undefBehaviourClass.get()->nonreturnTypeUB(); 14 | undefBehaviourClass.get()->accessDanglingReference(); 15 | //undefBehaviourClass.get()->intDivisionByZero(); 16 | //undefBehaviourClass.get()->shiftingInvalidNumber(); 17 | //undefBehaviourClass.get()->incorrectPairingMemAlloc(); 18 | //undefBehaviourClass.get()->signedIntegerOverflow(); 19 | //undefBehaviourClass.get()->incorrectPairingMemAlloc(); 20 | } -------------------------------------------------------------------------------- /44-UndefinedBehaviour/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/44-UndefinedBehaviour/main.exe -------------------------------------------------------------------------------- /45-CopyEllision/CopyEllision.cpp: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #include "CopyEllision.h" 3 | 4 | CopyEllision::CopyEllision() 5 | { 6 | } 7 | 8 | void CopyEllision::quaranteedCpyEllision(){ 9 | //Normally, elision is an optimization. While virtually every compiler support copy elision in the simplest of cases, 10 | //having elision still places a particular burden on users. Namely, the type who's copy/move is being elided must still 11 | //have the copy/move operation that was elided. 12 | //This might be useful in cases where a_mutex is a mutex that is privately held by some system, yet an external user 13 | //might want to have a scoped lock to it. 14 | std::lock_guard the_lock = getLock(); 15 | 16 | //Since the result of get_lock is a prvalue expression being used to initialize an object of the same type, no copying 17 | //or moving will happen. That expression never creates a temporary; it is used to directly initialize the_lock. There is 18 | //no elision because there is no copy/move to be elided elide. 19 | 20 | } 21 | 22 | void CopyEllision::parameterEllision(std::string str){ 23 | //When you pass an argument to a function, and the argument is a prvalue expression of the function's parameter 24 | //type, and this type is not a reference, then the prvalue's construction can be elided. 25 | std::cout<<"Parameter Ellision: "< 5 | #include 6 | #include 7 | 8 | 9 | class CopyEllision 10 | { 11 | public: 12 | CopyEllision(); 13 | std::mutex my_mutex; 14 | inline void getLock(){ 15 | return std::lock_guard(my_mutex); 16 | } 17 | void quaranteedCpyEllision(); 18 | void parameterEllision(std::string str); 19 | std::string returnValEllision(); 20 | }; 21 | 22 | #endif -------------------------------------------------------------------------------- /45-CopyEllision/main.cpp: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #include "CopyEllision.h" 3 | int main() 4 | { 5 | std::unique_ptr copyEllisionClass = std::make_unique(); 6 | 7 | //undefBehaviourClass.get()->readingOrWritingnullPointer(); 8 | //undefBehaviourClass.get()->unInitVariable(); 9 | //undefBehaviourClass.get()->accessOutOfBoundsIndex(); 10 | undefBehaviourClass.get()->invalidPointerArithmetic(); 11 | undefBehaviourClass.get()->nonreturnTypeUB(); 12 | undefBehaviourClass.get()->accessDanglingReference(); 13 | undefBehaviourClass.get()->intDivisionByZero(); 14 | undefBehaviourClass.get()->shiftingInvalidNumber(); 15 | undefBehaviourClass.get()->incorrectPairingMemAlloc(); 16 | undefBehaviourClass.get()->signedIntegerOverflow(); 17 | undefBehaviourClass.get()->incorrectPairingMemAlloc(); 18 | } -------------------------------------------------------------------------------- /45-CopyEllision/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/45-CopyEllision/main.exe -------------------------------------------------------------------------------- /46-OverloadResolution/OverloadResolution.h: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #ifndef OVERLOADRESOLUTION_H 3 | #define OVERLOADRESOLUTION_H 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | class OverloadResolution 10 | { 11 | public: 12 | OverloadResolution(); 13 | void categorizeArgument(); 14 | void arithmeticPromConv(); 15 | void exactMatch(); 16 | void overloadingVolatily(); 17 | void ovlerloadingHierarchy(); 18 | }; 19 | 20 | #endif -------------------------------------------------------------------------------- /46-OverloadResolution/main.cpp: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #include "OverloadResolution.h" 3 | 4 | 5 | int main() 6 | { 7 | std::unique_ptr overloadRes = std::make_unique(); 8 | 9 | 10 | } -------------------------------------------------------------------------------- /46-OverloadResolution/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/46-OverloadResolution/main.exe -------------------------------------------------------------------------------- /47-ConstExpr/ConstExpr.h: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #ifndef OVERLOADRESOLUTION_H 3 | #define OVERLOADRESOLUTION_H 4 | #include 5 | #include 6 | #include 7 | /* constexpr is a keyword that can be used to mark a variable's value as a constant expression, a function as 8 | potentially usable in constant expressions, or (since C++17) an if statement as having only one of its branches 9 | selected to be compiled */ 10 | class ConstExpr 11 | { 12 | public: 13 | ConstExpr(); 14 | void constExpVariable(); 15 | void staticIfStatement(); 16 | void constExprFunction(); 17 | 18 | }; 19 | 20 | #endif -------------------------------------------------------------------------------- /47-ConstExpr/main.cpp: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #include "ConstExpr.h" 3 | 4 | 5 | int main() 6 | { 7 | std::unique_ptr constExpr = std::make_unique(); 8 | 9 | constExpr.get()->constExpVariable(); 10 | constExpr.get()->staticIfStatement(); 11 | } -------------------------------------------------------------------------------- /47-ConstExpr/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/47-ConstExpr/main.exe -------------------------------------------------------------------------------- /48-MemoryManagement/MemoryManagement.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/48-MemoryManagement/MemoryManagement.exe -------------------------------------------------------------------------------- /48-MemoryManagement/MemoryManagement.h: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #ifndef MEMORYMANAGEMENT_H 3 | #define MEMORYMANAGEMENT_H 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | class MemoryManagement 10 | { 11 | public: 12 | MemoryManagement(); 13 | 14 | void freeStorage(); 15 | void freeStorageExOne(); 16 | void placementNew(); 17 | 18 | void stackOp(); 19 | void stack(); 20 | 21 | }; 22 | 23 | #endif -------------------------------------------------------------------------------- /48-MemoryManagement/main.cpp: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #include "MemoryManagement.h" 3 | 4 | 5 | int main() 6 | { 7 | std::unique_ptr memManagement = std::make_unique(); 8 | memManagement.get()->stack(); 9 | 10 | 11 | } -------------------------------------------------------------------------------- /48-MemoryManagement/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/48-MemoryManagement/main.exe -------------------------------------------------------------------------------- /49-StaticAssert copy/StaticAssert.cpp: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #include "CopyEllision.h" 3 | 4 | CopyEllision::CopyEllision() 5 | { 6 | } 7 | 8 | void CopyEllision::quaranteedCpyEllision(){ 9 | //Normally, elision is an optimization. While virtually every compiler support copy elision in the simplest of cases, 10 | //having elision still places a particular burden on users. Namely, the type who's copy/move is being elided must still 11 | //have the copy/move operation that was elided. 12 | //This might be useful in cases where a_mutex is a mutex that is privately held by some system, yet an external user 13 | //might want to have a scoped lock to it. 14 | std::lock_guard the_lock = getLock(); 15 | 16 | //Since the result of get_lock is a prvalue expression being used to initialize an object of the same type, no copying 17 | //or moving will happen. That expression never creates a temporary; it is used to directly initialize the_lock. There is 18 | //no elision because there is no copy/move to be elided elide. 19 | 20 | } 21 | 22 | void CopyEllision::parameterEllision(std::string str){ 23 | //When you pass an argument to a function, and the argument is a prvalue expression of the function's parameter 24 | //type, and this type is not a reference, then the prvalue's construction can be elided. 25 | std::cout<<"Parameter Ellision: "< 5 | #include 6 | #include 7 | // Assertations mean that a condition should be checked and if it's false, it's an error. For static_assert(), this is 8 | // done compile-time. 9 | 10 | class StaticAssert 11 | { 12 | public: 13 | StaticAssert(); 14 | 15 | template 16 | T multiplicationby10(const T t) 17 | { 18 | static_assert(std::is_integral::value, "multplication() only works for integral types"); 19 | return (t << 3) + (t << 1); 20 | } 21 | 22 | /* A static_assert() has a mandatory first parameter, the condition, that is a bool constexpr. It might have a second 23 | parameter, the message, that is a string literal. From C++17, the second parameter is optional; before that, it's 24 | mandatory. */ 25 | template 26 | T multiplicationby10(const T t) 27 | { 28 | static_assert(std::is_integral::value); 29 | return (t << 3) + (t << 1); 30 | } 31 | 32 | /* It is used when: 33 | In general, a verification at compile-time is required on some type on constexpr value 34 | A template function needs to verify certain properties of a type passed to it 35 | One wants to write test cases for: 36 | template metafunctions 37 | constexpr functions 38 | macro metaprogramming 39 | Certain defines are required (for ex., C++ version) 40 | Porting legacy code, assertations on sizeof(T) (e.g., 32-bit int) 41 | Certain compiler features are required for the program to work (packing, empty base class optimization, etc.) */ 42 | 43 | }; 44 | 45 | #endif -------------------------------------------------------------------------------- /49-StaticAssert copy/main.cpp: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #include "CopyEllision.h" 3 | 4 | 5 | int main() 6 | { 7 | std::unique_ptr copyEllisionClass = std::make_unique(); 8 | 9 | //undefBehaviourClass.get()->readingOrWritingnullPointer(); 10 | //undefBehaviourClass.get()->unInitVariable(); 11 | //undefBehaviourClass.get()->accessOutOfBoundsIndex(); 12 | undefBehaviourClass.get()->invalidPointerArithmetic(); 13 | undefBehaviourClass.get()->nonreturnTypeUB(); 14 | undefBehaviourClass.get()->accessDanglingReference(); 15 | undefBehaviourClass.get()->intDivisionByZero(); 16 | undefBehaviourClass.get()->shiftingInvalidNumber(); 17 | undefBehaviourClass.get()->incorrectPairingMemAlloc(); 18 | undefBehaviourClass.get()->signedIntegerOverflow(); 19 | undefBehaviourClass.get()->incorrectPairingMemAlloc(); 20 | } -------------------------------------------------------------------------------- /49-StaticAssert copy/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/49-StaticAssert copy/main.exe -------------------------------------------------------------------------------- /50-CallableObjects/CallableObjects.cpp: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #include "CallableObjects.h" 3 | 4 | CallableObjects::CallableObjects() 5 | { 6 | } 7 | 8 | bool CallableObjects::lessThanInt(int first, int second) 9 | { 10 | 11 | return first < second; 12 | } 13 | 14 | bool CallableObjects::GreaterThanInt::cmp(int first, int second) 15 | { 16 | return first > second; 17 | } 18 | 19 | void CallableObjects::sortVectorInt(std::vector &v, LessThanFunctionPtr lessThan) 20 | { 21 | if (v.size() < 2) 22 | return; 23 | 24 | if (v.size() == 2) 25 | { 26 | if (!lessThan(v.front(), v.back())) // Invoke the function pointer 27 | std::swap(v.front(), v.back()); 28 | return; 29 | } 30 | std::sort(v, lessThan); 31 | } 32 | 33 | void CallableObjects::applyFunctions() 34 | { 35 | std::vector intVecVars = {20,30,15,40}; 36 | 37 | sortVectorInt(intVecVars,lessThanInt); 38 | sortVectorInt(intVecVars,&GreaterThanInt::cmp); 39 | } 40 | -------------------------------------------------------------------------------- /50-CallableObjects/CallableObjects.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/50-CallableObjects/CallableObjects.exe -------------------------------------------------------------------------------- /50-CallableObjects/CallableObjects.h: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #ifndef CALLABLEOBJECTS_H 3 | #define CALLABLEOBJECTS_H 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | /* Callable objects are the collection of all C++ structures which can be used as a function. In practice, this are all 10 | things you can pass to the C++17 STL function invoke() or which can be used in the constructor of std::function, this 11 | includes: Function pointers, Classes with operator(), Classes with implicit conversions, References to functions, 12 | Pointers to member functions, Pointers to member data, lambdas. The callable objects are used in many STL 13 | algorithms as predicate. */ 14 | 15 | /* typedef returnType(*name)(arguments); // All 16 | using name = returnType(*)(arguments); // <= C++11 17 | using name = std::add_pointer::type; // <= C++11 18 | using name = std::add_pointer_t; // <= C++14 */ 19 | 20 | using LessThanFunctionPtr = std::add_pointer; 21 | 22 | class CallableObjects 23 | { 24 | public: 25 | CallableObjects(); 26 | 27 | bool lessThanInt(int first, int second); 28 | typedef struct GreaterThanInt {static bool cmp(int first, int second);} GreaterThanInt; 29 | void sortVectorInt(std::vector &v, LessThanFunctionPtr lessThan); 30 | 31 | void applyFunctions(); 32 | 33 | 34 | 35 | }; 36 | 37 | #endif -------------------------------------------------------------------------------- /50-CallableObjects/main.cpp: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #include "CallableObjects.h" 3 | 4 | 5 | int main() 6 | { 7 | std::unique_ptr callableObjects = std::make_unique(); 8 | callableObjects.get()->applyFunctions(); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /50-CallableObjects/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/50-CallableObjects/main.exe -------------------------------------------------------------------------------- /51-BitManipulators/BitManipulators.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/51-BitManipulators/BitManipulators.exe -------------------------------------------------------------------------------- /51-BitManipulators/BitManipulators.h: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #ifndef BITMANIPULATORS_H 3 | #define BITMANIPULATORS_H 4 | #include 5 | #include 6 | #include 7 | /* In the BitManipulation class, we will cover useful functions that are generally used in communication protocols and embedded systems.*/ 8 | class BitManipulators 9 | { 10 | public: 11 | BitManipulators(); 12 | 13 | void generalBitManipulation(); 14 | void bitsetBitManipulation(); 15 | 16 | 17 | }; 18 | 19 | #endif -------------------------------------------------------------------------------- /51-BitManipulators/main.cpp: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #include "BitManipulators.h" 3 | 4 | 5 | int main() 6 | { 7 | std::unique_ptr bitManipulation = std::make_unique(); 8 | 9 | bitManipulation.get()->generalBitManipulation(); 10 | bitManipulation.get()->bitsetBitManipulation(); 11 | 12 | } 13 | 14 | -------------------------------------------------------------------------------- /51-BitManipulators/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/51-BitManipulators/main.exe -------------------------------------------------------------------------------- /52-JSON_File/JsonFileReader.h: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #ifndef JSONFILEREADER_H 3 | #define JSONFILEREADER_H 4 | #include 5 | #include 6 | #include 7 | #include "json/json.h" 8 | #include 9 | #include 10 | #include 11 | /* In the BitManipulation class, we will cover useful functions that are generally used in communication protocols and embedded systems.*/ 12 | class JsonFileReader 13 | { 14 | public: 15 | JsonFileReader(); 16 | JsonFileReader(JsonFileReader &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 17 | JsonFileReader(const JsonFileReader &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 18 | JsonFileReader &operator=(const JsonFileReader &ruleOfThree) = delete; // III. COPY ASSIGNMENT 19 | ~JsonFileReader() = default; 20 | 21 | struct JsonSettings{ 22 | Json::Value root1; 23 | Json::Value root2; 24 | Json::CharReaderBuilder builder; 25 | std::ifstream inputFileStream; 26 | std::string fileName; 27 | JSONCPP_STRING errs; 28 | }jsonSettings; 29 | 30 | void initJsonFileSettings(const std::string &pFolderName, const std::string &pFileName); 31 | void parseJsonFile(Json::Value &root); 32 | void seperateParameters(Json::Value &root); 33 | 34 | }; 35 | 36 | #endif -------------------------------------------------------------------------------- /52-JSON_File/JsonFileWriter.cpp: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #include "JsonFileWriter.h" 3 | 4 | 5 | JsonFileWriter::JsonFileWriter() 6 | { 7 | 8 | } 9 | 10 | void JsonFileWriter::initJsonFileSettings(const std::string &pFolderName, const std::string &pFileName){ 11 | jsonSettings.outputFileStream.open(pFolderName+pFileName,std::ofstream::out | std::ofstream::trunc); 12 | jsonSettings.outputFileStream<<""; 13 | jsonSettings.writer = std::unique_ptr(jsonSettings.builder.newStreamWriter()); 14 | } 15 | 16 | Json::Value JsonFileWriter::createArray(int Type1, std::string Type2, std::string Type3){ 17 | Json::Value elements; 18 | elements["ID"] = Type1; 19 | elements["Type"] = Type2; 20 | elements["Name"] = Type3; 21 | return elements; 22 | } 23 | 24 | void JsonFileWriter::createJsonFile(){ 25 | 26 | //Json Elements 27 | jsonSettings.root["Vehicle Types"] = "UAV"; 28 | jsonSettings.root["Company Name"] = "Bayraktar, Tai"; 29 | jsonSettings.root["Army Use Area"] = "Air Forces"; 30 | 31 | //Creating array type json variable 32 | jsonSettings.root["Definition"][0] = createArray(1, "UAV", "TB2"); 33 | jsonSettings.root["Definition"][1] = createArray(2, "UAV", "AKINCI"); 34 | jsonSettings.root["Definition"][2] = createArray(3, "UAV", "AKSUNGUR"); 35 | jsonSettings.root["Definition"][3] = createArray(4, "UAV", "AKINCI"); 36 | 37 | //Print all variables 38 | /* for(auto &item: jsonSettings.root.getMemberNames()){ 39 | std::cout<write(jsonSettings.root, &jsonSettings.outputFileStream); 47 | jsonSettings.outputFileStream.close(); 48 | } 49 | -------------------------------------------------------------------------------- /52-JSON_File/JsonFileWriter.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/52-JSON_File/JsonFileWriter.exe -------------------------------------------------------------------------------- /52-JSON_File/JsonFileWriter.h: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #ifndef JSONFILEWRITER_H 3 | #define JSONFILEWRITER_H 4 | #include 5 | #include 6 | #include 7 | #include "json/json.h" 8 | #include 9 | #include 10 | #include 11 | /* In the BitManipulation class, we will cover useful functions that are generally used in communication protocols and embedded systems.*/ 12 | class JsonFileWriter 13 | { 14 | public: 15 | JsonFileWriter(); 16 | JsonFileWriter(JsonFileWriter &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 17 | JsonFileWriter(const JsonFileWriter &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 18 | JsonFileWriter &operator=(const JsonFileWriter &ruleOfThree) = delete; // III. COPY ASSIGNMENT 19 | ~JsonFileWriter() = default; 20 | 21 | struct JsonSettings{ 22 | Json::Value root; 23 | Json::StreamWriterBuilder builder; 24 | std::unique_ptr writer; 25 | std::ofstream outputFileStream; 26 | }jsonSettings; 27 | 28 | void initJsonFileSettings(const std::string &pFolderName, const std::string &pFileName); 29 | void createJsonFile(); 30 | Json::Value createArray(int Type1, std::string Type2, std::string Type3); 31 | }; 32 | 33 | #endif -------------------------------------------------------------------------------- /52-JSON_File/main.cpp: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #include "JsonFileWriter.h" 3 | #include "JsonFileReader.h" 4 | 5 | #include 6 | 7 | int main(int argc, char **argv) 8 | { 9 | std::unique_ptr firstJsonFileWriter = std::make_unique(); 10 | std::unique_ptr secondJsonFileWriter = std::make_unique(); 11 | 12 | std::unique_ptr jsonFileReader= std::make_unique(); 13 | 14 | firstJsonFileWriter.get()->initJsonFileSettings(std::filesystem::current_path().string(),"/52-JSON_File/test1.json"); 15 | firstJsonFileWriter.get()->createJsonFile(); 16 | 17 | secondJsonFileWriter.get()->initJsonFileSettings(std::filesystem::current_path().string(),"/52-JSON_File/test2.json"); 18 | secondJsonFileWriter.get()->createJsonFile(); 19 | 20 | jsonFileReader.get()->initJsonFileSettings(std::filesystem::current_path().string(),"/52-JSON_File/test1.json"); 21 | jsonFileReader.get()->parseJsonFile(jsonFileReader->jsonSettings.root1); 22 | 23 | jsonFileReader.get()->initJsonFileSettings(std::filesystem::current_path().string(),"/52-JSON_File/test2.json"); 24 | jsonFileReader.get()->parseJsonFile(jsonFileReader->jsonSettings.root2); 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /52-JSON_File/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/52-JSON_File/main.exe -------------------------------------------------------------------------------- /52-JSON_File/test1.json: -------------------------------------------------------------------------------- 1 | { 2 | "Army Use Area" : "Air Forces", 3 | "Company Name" : "Bayraktar, Tai", 4 | "Definition" : 5 | [ 6 | { 7 | "ID" : 1, 8 | "Name" : "TB2", 9 | "Type" : "UAV" 10 | }, 11 | { 12 | "ID" : 2, 13 | "Name" : "AKINCI", 14 | "Type" : "UAV" 15 | }, 16 | { 17 | "ID" : 3, 18 | "Name" : "AKSUNGUR", 19 | "Type" : "UAV" 20 | }, 21 | { 22 | "ID" : 4, 23 | "Name" : "AKINCI", 24 | "Type" : "UAV" 25 | } 26 | ], 27 | "Vehicle Types" : "UAV" 28 | } -------------------------------------------------------------------------------- /52-JSON_File/test2.json: -------------------------------------------------------------------------------- 1 | { 2 | "Army Use Area" : "Air Forces", 3 | "Company Name" : "Bayraktar, Tai", 4 | "Definition" : 5 | [ 6 | { 7 | "ID" : 1, 8 | "Name" : "TB2", 9 | "Type" : "UAV" 10 | }, 11 | { 12 | "ID" : 2, 13 | "Name" : "AKINCI", 14 | "Type" : "UAV" 15 | }, 16 | { 17 | "ID" : 3, 18 | "Name" : "AKSUNGUR", 19 | "Type" : "UAV" 20 | }, 21 | { 22 | "ID" : 4, 23 | "Name" : "AKINCI", 24 | "Type" : "UAV" 25 | } 26 | ], 27 | "Vehicle Types" : "UAV" 28 | } -------------------------------------------------------------------------------- /53-Algorithm/Algorithm-Examples/ArrayExamples.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/53-Algorithm/Algorithm-Examples/ArrayExamples.exe -------------------------------------------------------------------------------- /53-Algorithm/Algorithm-Examples/ArrayExamples.h: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #ifndef ARRAYEXAMPLES_H 3 | #define ARRAYEXAMPLES_H 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class ArrayExamples 13 | { 14 | public: 15 | ArrayExamples(); 16 | ArrayExamples(int val) = delete; 17 | ArrayExamples(ArrayExamples &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 18 | ArrayExamples(const ArrayExamples &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 19 | ArrayExamples &operator=(const ArrayExamples &ruleOfThree) = delete; // III. COPY ASSIGNMENT 20 | ~ArrayExamples() =default; 21 | 22 | void removeDuplicatesFromSortedArray(); 23 | void rotateArray(); 24 | void firstNonRepeatedCharacterIndex(); 25 | void containsDuplicate(); 26 | void singleNumber(); 27 | void intersectionOfTwoArrays(); 28 | void findSecondLargestElementInArray(); 29 | }; 30 | 31 | #endif -------------------------------------------------------------------------------- /53-Algorithm/Algorithm-Examples/main.cpp: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #include "ArrayExamples.h" 3 | 4 | int main() 5 | { 6 | std::unique_ptr mArrayExample = std::make_unique(); 7 | 8 | //ArrayExample 9 | mArrayExample.get()->removeDuplicatesFromSortedArray(); 10 | mArrayExample.get()->rotateArray(); 11 | mArrayExample.get()->firstNonRepeatedCharacterIndex(); 12 | mArrayExample.get()->containsDuplicate(); 13 | mArrayExample.get()->singleNumber(); 14 | mArrayExample.get()->intersectionOfTwoArrays(); 15 | mArrayExample.get()->findSecondLargestElementInArray(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /53-Algorithm/Algorithm-Examples/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/53-Algorithm/Algorithm-Examples/main.exe -------------------------------------------------------------------------------- /53-Algorithm/ComparisonAlgorithm.h: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #ifndef COMPARISONALGORITHM_H 3 | #define COMPARISONALGORITHM_H 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #define print(a) std::cout << a 10 | #define printOneLine(a) std::cout << a << std::endl 11 | #define printTwoLine(a,b) std::cout << a << b << std::endl 12 | // An algorithm is a strategy for performing a particular task such as sorting or searching.These algorithms implemented as function so they work 13 | // on most of the different container types.ALGORİTHMs are not generally part of the containers.It is necessary in order to support generic programming in the standart library 14 | //Note that generic algorithms do not wok directly ont he containers .They use intermediate that called an iterator 15 | class ComparisonAlgorithm 16 | { 17 | public: 18 | ComparisonAlgorithm(); 19 | ComparisonAlgorithm(int val) = delete; 20 | ComparisonAlgorithm(ComparisonAlgorithm &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 21 | ComparisonAlgorithm(const ComparisonAlgorithm &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 22 | ComparisonAlgorithm &operator=(const ComparisonAlgorithm &ruleOfThree) = delete; // III. COPY ASSIGNMENT 23 | ~ComparisonAlgorithm() = default; 24 | 25 | void comparisonAlgorithms(); 26 | }; 27 | 28 | #endif -------------------------------------------------------------------------------- /53-Algorithm/CountingAlgorithm.h: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #ifndef COUNTINGALGORITHM_H 3 | #define COUNTINGALGORITHM_H 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #define print(a) std::cout << a 10 | #define printOneLine(a) std::cout << a << std::endl 11 | #define printTwoLine(a,b) std::cout << a << b << std::endl 12 | // An algorithm is a strategy for performing a particular task such as sorting or searching.These algorithms implemented as function so they work 13 | // on most of the different container types.ALGORİTHMs are not generally part of the containers.It is necessary in order to support generic programming in the standart library 14 | //Note that generic algorithms do not wok directly ont he containers .They use intermediate that called an iterator 15 | class CountingAlgorithm 16 | { 17 | public: 18 | CountingAlgorithm(); 19 | CountingAlgorithm(int val) = delete; 20 | CountingAlgorithm(CountingAlgorithm &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 21 | CountingAlgorithm(const CountingAlgorithm &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 22 | CountingAlgorithm &operator=(const CountingAlgorithm &ruleOfThree) = delete; // III. COPY ASSIGNMENT 23 | ~CountingAlgorithm() = default; 24 | 25 | void vectorInitializations(); 26 | void countingAlgortihms(); 27 | }; 28 | 29 | #endif -------------------------------------------------------------------------------- /53-Algorithm/ModifyingSequenceAlgorithm.h: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #ifndef MODIFYINGSEQUENCEALGORTITHM_H 3 | #define MODIFYINGSEQUENCEALGORTITHM_H 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #define print(a) std::cout << a 11 | #define printOneLine(a) std::cout << a << std::endl 12 | #define printTwoLine(a,b) std::cout << a << b << std::endl 13 | // An algorithm is a strategy for performing a particular task such as sorting or searching.These algorithms implemented as function so they work 14 | // on most of the different container types.ALGORİTHMs are not generally part of the containers.It is necessary in order to support generic programming in the standart library 15 | //Note that generic algorithms do not wok directly ont he containers .They use intermediate that called an iterator 16 | class ModifyingSequenceAlgorithm 17 | { 18 | public: 19 | ModifyingSequenceAlgorithm(); 20 | ModifyingSequenceAlgorithm(int val) = delete; 21 | ModifyingSequenceAlgorithm(ModifyingSequenceAlgorithm &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 22 | ModifyingSequenceAlgorithm(const ModifyingSequenceAlgorithm &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 23 | ModifyingSequenceAlgorithm &operator=(const ModifyingSequenceAlgorithm &ruleOfThree) = delete; // III. COPY ASSIGNMENT 24 | ~ModifyingSequenceAlgorithm() = default; 25 | 26 | void copyFunctions(); 27 | void fillFunctions(); 28 | void generateFunctions(); 29 | void moveFunctions(); 30 | void removeFunctions(); 31 | void replaceFunctions(); 32 | void reverseFunctions(); 33 | void rotateFunctions(); 34 | void sampleShuffleFunctions(); 35 | void transformFunctions(); 36 | void uniqueFunctions(); 37 | }; 38 | 39 | #endif -------------------------------------------------------------------------------- /53-Algorithm/SearchAlgorithms.h: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #ifndef SEARCHALGORITHMS_H 3 | #define SEARCHALGORITHMS_H 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #define print(a) std::cout << a 10 | #define printOneLine(a) std::cout << a << std::endl 11 | #define printTwoLine(a,b) std::cout << a << b << std::endl 12 | // An algorithm is a strategy for performing a particular task such as sorting or searching.These algorithms implemented as function so they work 13 | // on most of the different container types.ALGORİTHMs are not generally part of the containers.It is necessary in order to support generic programming in the standart library 14 | //Note that generic algorithms do not wok directly ont he containers .They use intermediate that called an iterator 15 | class SearchAlgorithms 16 | { 17 | public: 18 | SearchAlgorithms(); 19 | SearchAlgorithms(int val) = delete; 20 | SearchAlgorithms(SearchAlgorithms &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 21 | SearchAlgorithms(const SearchAlgorithms &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 22 | SearchAlgorithms &operator=(const SearchAlgorithms &ruleOfThree) = delete; // III. COPY ASSIGNMENT 23 | ~SearchAlgorithms() = default; 24 | 25 | void searchAlgorithms(); 26 | int manualAlgorithm(std::vector::iterator begin, std::vector::iterator end,const int &pVar); 27 | void binarySearchAlgorithms(); 28 | }; 29 | 30 | #endif -------------------------------------------------------------------------------- /53-Algorithm/SetAndOperationalAlgorithms.h: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #ifndef SETANDOPERATIONALALGORITHMS_H 3 | #define SETANDOPERATIONALALGORITHMS_H 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #define print(a) std::cout << a 10 | #define printOneLine(a) std::cout << a << std::endl 11 | #define printTwoLine(a,b) std::cout << a << b << std::endl 12 | // An algorithm is a strategy for performing a particular task such as sorting or searching.These algorithms implemented as function so they work 13 | // on most of the different container types.ALGORİTHMs are not generally part of the containers.It is necessary in order to support generic programming in the standart library 14 | //Note that generic algorithms do not wok directly ont he containers .They use intermediate that called an iterator 15 | class SetAndOperationalAlgorithms 16 | { 17 | public: 18 | SetAndOperationalAlgorithms(); 19 | SetAndOperationalAlgorithms(int val) = delete; 20 | SetAndOperationalAlgorithms(SetAndOperationalAlgorithms &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 21 | SetAndOperationalAlgorithms(const SetAndOperationalAlgorithms &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 22 | SetAndOperationalAlgorithms &operator=(const SetAndOperationalAlgorithms &ruleOfThree) = delete; // III. COPY ASSIGNMENT 23 | ~SetAndOperationalAlgorithms() = default; 24 | 25 | void setAlgorithm(); 26 | void operationalAlgorithm(); 27 | }; 28 | 29 | #endif -------------------------------------------------------------------------------- /53-Algorithm/SortingAlgorithms.h: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #ifndef SORTINGALGORITHMS_H 3 | #define SORTINGALGORITHMS_H 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #define print(a) std::cout << a 10 | #define printOneLine(a) std::cout << a << std::endl 11 | #define printTwoLine(a,b) std::cout << a << b << std::endl 12 | // An algorithm is a strategy for performing a particular task such as sorting or searching.These algorithms implemented as function so they work 13 | // on most of the different container types.ALGORİTHMs are not generally part of the containers.It is necessary in order to support generic programming in the standart library 14 | //Note that generic algorithms do not wok directly ont he containers .They use intermediate that called an iterator 15 | class SortingAlgorithms 16 | { 17 | public: 18 | SortingAlgorithms(); 19 | SortingAlgorithms(int val) = delete; 20 | SortingAlgorithms(SortingAlgorithms &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 21 | SortingAlgorithms(const SortingAlgorithms &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 22 | SortingAlgorithms &operator=(const SortingAlgorithms &ruleOfThree) = delete; // III. COPY ASSIGNMENT 23 | ~SortingAlgorithms() = default; 24 | 25 | void sortingFunction(); 26 | }; 27 | 28 | #endif -------------------------------------------------------------------------------- /53-Algorithm/SwapAndExchangeAlgorithms.cpp: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #include "SwapAndExchangeAlgorithms.h" 3 | 4 | SwapAndExchangeAlgorithms::SwapAndExchangeAlgorithms() 5 | { 6 | } 7 | 8 | void SwapAndExchangeAlgorithms::swapAndExchangeFunctions(){ 9 | //WE WILL CONSIDER 10 | //std::iter_swap, std::swap_range, std::swap, std::exchange 11 | 12 | printOneLine("----SWAP AND EXCHANGE ALGORITHMS----"); 13 | 14 | printOneLine("-----------std::iter_swap-----------"); 15 | //std::iter_swap 16 | //Swaps two elements or sequence of elements 17 | std::vector setSwapVec{1,4,3,2,7,6,5,8,9,10}; 18 | //Sorting op 19 | for (std::vector::iterator i = setSwapVec.begin(); i != setSwapVec.end(); ++i) 20 | std::iter_swap(i, std::min_element(i, setSwapVec.end())); 21 | 22 | 23 | for (auto &n: setSwapVec){ 24 | print(n); 25 | } 26 | printOneLine(""); 27 | //---------------------------------------------------------------------------------- 28 | 29 | printOneLine("-----------std::swap_range-----------"); 30 | //std::swap_range 31 | //Swaps two elements or sequence of elements 32 | std::vector setSwapRangeFirstVec{1,4,3,2,7,6}; 33 | std::vector setSwapRangeSecondVec{20,30,40,50,60,70}; 34 | 35 | std::swap_ranges(setSwapRangeFirstVec.begin(),setSwapRangeFirstVec.begin()+3, setSwapRangeSecondVec.begin()); 36 | 37 | 38 | for (auto &n: setSwapRangeFirstVec){ 39 | print(n); 40 | } 41 | printOneLine(""); 42 | //---------------------------------------------------------------------------------- 43 | 44 | printOneLine("-----------std::swap-----------"); 45 | //std::swap_ranges 46 | //Swaps two elements or sequence of elements 47 | std::vector setSwapFirstVec{1,4,3,2,7,6}; 48 | std::vector setSwapSecondVec{20,30,40,50,60,70}; 49 | 50 | std::swap(setSwapFirstVec,setSwapSecondVec); 51 | 52 | 53 | for (auto &n: setSwapFirstVec){ 54 | print(n); 55 | } 56 | printOneLine(""); 57 | //---------------------------------------------------------------------------------- 58 | } -------------------------------------------------------------------------------- /53-Algorithm/SwapAndExchangeAlgorithms.h: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #ifndef SWAPANDEXCHANGEALGORITHMS_H 3 | #define SWAPANDEXCHANGEALGORITHMS_H 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #define print(a) std::cout << a 10 | #define printOneLine(a) std::cout << a << std::endl 11 | #define printTwoLine(a,b) std::cout << a << b << std::endl 12 | // An algorithm is a strategy for performing a particular task such as sorting or searching.These algorithms implemented as function so they work 13 | // on most of the different container types.ALGORİTHMs are not generally part of the containers.It is necessary in order to support generic programming in the standart library 14 | //Note that generic algorithms do not wok directly ont he containers .They use intermediate that called an iterator 15 | class SwapAndExchangeAlgorithms 16 | { 17 | public: 18 | SwapAndExchangeAlgorithms(); 19 | SwapAndExchangeAlgorithms(int val) = delete; 20 | SwapAndExchangeAlgorithms(SwapAndExchangeAlgorithms &&ruleOfFive) noexcept = delete; //III. MOVE CONSTRUCTOR 21 | SwapAndExchangeAlgorithms(const SwapAndExchangeAlgorithms &ruleOfThree) = delete; // II. COPY CONSTRUCTOR 22 | SwapAndExchangeAlgorithms &operator=(const SwapAndExchangeAlgorithms &ruleOfThree) = delete; // III. COPY ASSIGNMENT 23 | ~SwapAndExchangeAlgorithms() = default; 24 | 25 | void swapAndExchangeFunctions(); 26 | }; 27 | 28 | #endif -------------------------------------------------------------------------------- /53-Algorithm/main.cpp: -------------------------------------------------------------------------------- 1 | //Author: Burak Doğançay 2 | #include "CountingAlgorithm.h" 3 | #include "SearchAlgorithms.h" 4 | #include "SetAndOperationalAlgorithms.h" 5 | #include "ComparisonAlgorithm.h" 6 | #include "ModifyingSequenceAlgorithm.h" 7 | #include "SwapAndExchangeAlgorithms.h" 8 | #include "SortingAlgorithms.h" 9 | int main() 10 | { 11 | std::unique_ptr mCountingAlgorithm = std::make_unique(); 12 | std::unique_ptr mSearchAlgorithm = std::make_unique(); 13 | std::unique_ptr mSetAndOpAlgorithm = std::make_unique(); 14 | std::unique_ptr mComparisonAlgorithms = std::make_unique(); 15 | std::unique_ptr mModifyingAlgorithms = std::make_unique(); 16 | std::unique_ptr mSwapAndExchangeAlgorithm = std::make_unique(); 17 | std::unique_ptr mSortingAlgorithms = std::make_unique(); 18 | 19 | mCountingAlgorithm.get()->vectorInitializations(); 20 | mCountingAlgorithm.get()->countingAlgortihms(); 21 | mSearchAlgorithm.get()->searchAlgorithms(); 22 | mSearchAlgorithm.get()->binarySearchAlgorithms(); 23 | mSetAndOpAlgorithm.get()->setAlgorithm(); 24 | mSetAndOpAlgorithm.get()->operationalAlgorithm(); 25 | mComparisonAlgorithms.get()->comparisonAlgorithms(); 26 | mModifyingAlgorithms.get()->copyFunctions(); 27 | mModifyingAlgorithms.get()->fillFunctions(); 28 | mModifyingAlgorithms.get()->generateFunctions(); 29 | mModifyingAlgorithms.get()->moveFunctions(); 30 | mModifyingAlgorithms.get()->removeFunctions(); 31 | mModifyingAlgorithms.get()->replaceFunctions(); 32 | 33 | mSwapAndExchangeAlgorithm.get()->swapAndExchangeFunctions(); 34 | mSortingAlgorithms.get()->sortingFunction(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /53-Algorithm/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/53-Algorithm/main.exe -------------------------------------------------------------------------------- /54-XML_File/Test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /54-XML_File/main.cpp: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #include "XmlController.h" 3 | #include 4 | 5 | int main(int argc, char **argv) 6 | { 7 | std::unique_ptr xmlController = std::make_unique(); 8 | 9 | xmlController.get()->init(); 10 | xmlController.get()->openXmlFile(std::filesystem::current_path().string(),"/54-XML_File/Test.xml"); 11 | xmlController.get()->uavElementsProcess(); 12 | xmlController.get()->loadAndDisplayAllXml(); 13 | xmlController.get()->findElementByTagName(); 14 | xmlController.get()->findElementByAttrName(); 15 | xmlController.get()->findChildNodes(); 16 | xmlController.get()->attributeTypes(); 17 | xmlController.get()->printXmlHeaders(); 18 | } 19 | -------------------------------------------------------------------------------- /54-XML_File/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/54-XML_File/main.exe -------------------------------------------------------------------------------- /55-FunctionPointers/FunctionPointers.cpp: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #include "FunctionPointers.h" 3 | FunctionPointers::FunctionPointers(): 4 | firstVar(0), 5 | secondVar(0) 6 | { 7 | } 8 | 9 | void FunctionPointers::callBackFunction(int pFirstVar, int pSecondVar, func func,FunctionPointers *givenClass){ 10 | 11 | firstVar = pFirstVar; 12 | secondVar = pSecondVar; 13 | std::cout<<"First Variable is: "<*func)(); 17 | //(givenClass->*f()); 18 | } 19 | 20 | void FunctionPointers::callBackFunctionStd(int pFirstVar, int pSecondVar, funcStd func,FunctionPointers *givenClass){ 21 | firstVar = pFirstVar; 22 | secondVar = pSecondVar; 23 | 24 | std::cout<<"First Variable is: "<*func)(pFirstVar,pSecondVar); 31 | } 32 | 33 | int FunctionPointers::callBackFunctionWithParamsStd(int pFirstVar, int pSecondVar, funcParamStd func){ 34 | return func(pFirstVar,pSecondVar); 35 | } 36 | 37 | void FunctionPointers::returnBiggestVariable(){ 38 | static int tVar; 39 | 40 | if(firstVar > secondVar) 41 | tVar=firstVar; 42 | else 43 | tVar=secondVar; 44 | 45 | std::cout<< "Biggest Variable is :"<< tVar << std::endl; 46 | } 47 | 48 | int FunctionPointers::multiplyProcess(int a,int b){ 49 | static int tMul; 50 | tMul = a*b; 51 | std::cout<<"Multiply two Variables : "< 4 | 5 | int main(int argc, char **argv) 6 | { 7 | std::unique_ptr functionPointers = std::make_unique(); 8 | functionPointers.get()->callBackFunction(20,30,&FunctionPointers::returnBiggestVariable,functionPointers.get()); 9 | functionPointers.get()->callBackFunctionStd(20,30,std::bind(&FunctionPointers::returnBiggestVariable, functionPointers.get()),functionPointers.get()); 10 | functionPointers.get()->callBackFunctionWithParams(20,30,&FunctionPointers::multiplyProcess); 11 | functionPointers.get()->callBackFunctionWithParamsStd(20,30,std::bind(FunctionPointers::multiplyProcess, functionPointers.get(), std::placeholders::_1,std::placeholders::_2)); 12 | } 13 | -------------------------------------------------------------------------------- /55-FunctionPointers/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/55-FunctionPointers/main.exe -------------------------------------------------------------------------------- /56-Database/Test.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/56-Database/Test.db -------------------------------------------------------------------------------- /56-Database/Test.sqbpro: -------------------------------------------------------------------------------- 1 |
2 | -------------------------------------------------------------------------------- /56-Database/main.cpp: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #include "DatabaseController.h" 3 | #include 4 | 5 | int main(int argc, char **argv) 6 | { 7 | std::unique_ptr databaseController = std::make_unique(); 8 | //Database Process Functions 9 | databaseController.get()->setClassInstance(databaseController.get()); 10 | databaseController.get()->openDatabase(std::filesystem::current_path().string(),"/56-Database/Test.db"); 11 | databaseController.get()->insertDataToTableProcess(); 12 | databaseController.get()->selectAndGetDataTableProcess(); 13 | databaseController.get()->infoForSqlData(); 14 | databaseController.get()->closeDatabase(databaseController.get()->mDataBaseFile); 15 | //---------------------------- 16 | } -------------------------------------------------------------------------------- /56-Database/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/56-Database/main.exe -------------------------------------------------------------------------------- /57-Stream/BinaryData.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/57-Stream/BinaryData.bin -------------------------------------------------------------------------------- /57-Stream/Data.txt: -------------------------------------------------------------------------------- 1 | Something somewhere -------------------------------------------------------------------------------- /57-Stream/DataOstream.txt: -------------------------------------------------------------------------------- 1 | Name : Burak 2 | Surname : Dogancay 3 | Age : 25 4 | City : Istanbul 5 | Country : Turkey 6 | PostCode : 34678 7 | -------------------------------------------------------------------------------- /57-Stream/StreamController.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/57-Stream/StreamController.exe -------------------------------------------------------------------------------- /57-Stream/main.cpp: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #include "StreamController.h" 3 | #include 4 | 5 | int main(int argc, char **argv) 6 | { 7 | std::unique_ptr streamController = std::make_unique(); 8 | 9 | //streamController.get()->ifStreamExample(); 10 | //streamController.get()->osStreamExample(); 11 | streamController.get()->isStreamExample(); 12 | 13 | //Serialize Data and create BinaryData.bin 14 | const std::string filename = "57-Stream/BinaryData.bin"; 15 | StreamController::UAVVehicles originalData = {(char*)"Tb2",(char*)"Baykar",50,23789}; 16 | streamController.get()->dataSerialize(originalData,filename); 17 | 18 | //Deserialize Data and read BinaryData.bin 19 | StreamController::UAVVehicles loadedData; 20 | streamController.get()->dataDeserialize(loadedData,filename); 21 | 22 | std::cout<<"----DESERIALIZE DATA---- : FROM : "< 4 | 5 | int main(int argc, char **argv) 6 | { 7 | std::unique_ptr stringOp = std::make_unique(); 8 | //--------------------------------------------- 9 | stringOp.get()->basicCharPointerStrEx(); 10 | //---------------------------- 11 | } -------------------------------------------------------------------------------- /58-StringOperations/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/58-StringOperations/main.exe -------------------------------------------------------------------------------- /59-File_IO_Operations/1-cstdio/NewExampleFile.txt: -------------------------------------------------------------------------------- 1 | Access is changed after freopen -------------------------------------------------------------------------------- /59-File_IO_Operations/1-cstdio/main.cpp: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #include "CStdioOperations.h" 3 | #include 4 | 5 | int main(int argc, char **argv) 6 | { 7 | std::unique_ptr cStdioOperations = std::make_unique(); 8 | std::string currentPath = std::filesystem::path(__FILE__).parent_path().string(); 9 | //--------------------------------------------- 10 | //OPERATION ON FILES 11 | /* cStdioOperations.get()->removeFunc(currentPath+"/RemoveFile.txt"); 12 | cStdioOperations.get()->renameFunc(currentPath, currentPath+"/NewExampleFile.txt"); 13 | cStdioOperations.get()->tmpFileFunc(); */ 14 | //---------------------------- 15 | 16 | //--------------------------------------------- 17 | //FILE ACCESS 18 | //cStdioOperations.get()->fcloseFunc(currentPath + "/NewExampleFile.txt"); 19 | //cStdioOperations.get()->fflushFunc(currentPath + "/NewExampleFile.txt"); 20 | //cStdioOperations.get()->fopenFunc(currentPath + "/NewExampleFile.txt"); 21 | cStdioOperations.get()->freopenFunc(currentPath + "/NewExampleFile.txt"); 22 | //---------------------------- 23 | 24 | //cStdioOperations.get()->fgetcFunc(currentPath + "/NewExampleFile.txt"); 25 | //cStdioOperations.get()->fgetposFunc(currentPath + "/NewExampleFile.txt"); 26 | } -------------------------------------------------------------------------------- /59-File_IO_Operations/1-cstdio/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/59-File_IO_Operations/1-cstdio/main.exe -------------------------------------------------------------------------------- /60-EventBaseExample/EventClasses.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTCLASSES_h 2 | #define EVENTCLASSES_h 3 | #include "EventTypes.h" 4 | #include "EventClassesInterface.h" 5 | class ButtonClickedEvent : public EventClassesInterface{ 6 | public: 7 | UIEventType getType() const override{ 8 | return UIEventType::BUTTON_CLICKED; 9 | } 10 | }; 11 | 12 | class TextChangedEvent : public EventClassesInterface{ 13 | public: 14 | UIEventType getType() const override{ 15 | return UIEventType::TEXT_CHANGED; 16 | } 17 | }; 18 | 19 | class DropDownChangedEvent : public EventClassesInterface{ 20 | public: 21 | UIEventType getType() const override{ 22 | return UIEventType::DROPDOWN_CHANGED; 23 | } 24 | }; 25 | 26 | //You can add other eventclasses,Also you can create each class seperately 27 | #endif -------------------------------------------------------------------------------- /60-EventBaseExample/EventClassesInterface.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTINTERFACE_H 2 | #define EVENTINTERFACE_H 3 | #include "EventTypes.h" 4 | class EventClassesInterface{ 5 | 6 | public: 7 | virtual ~EventClassesInterface() = default; 8 | virtual UIEventType getType() const = 0; 9 | }; 10 | #endif -------------------------------------------------------------------------------- /60-EventBaseExample/EventDispatcher.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/60-EventBaseExample/EventDispatcher.exe -------------------------------------------------------------------------------- /60-EventBaseExample/EventDispatcher.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTDISPATCHER_H 2 | #define EVENTDISPATCHER_H 3 | #include 4 | #include 5 | #include "EventListenersInterface.h" 6 | class EventDispatcher{ 7 | private: 8 | std::vector> listeners; 9 | 10 | public: 11 | void addListener(std::shared_ptr listener) 12 | { 13 | listeners.push_back(listener); 14 | } 15 | 16 | void dispatch(const EventClassesInterface& event) 17 | { 18 | for (const std::shared_ptr& listener : listeners) 19 | { 20 | listener->onEvent(event); 21 | } 22 | } 23 | 24 | }; 25 | #endif -------------------------------------------------------------------------------- /60-EventBaseExample/EventListeners.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTLISTENERS_H 2 | #define EVENTLISTENERS_H 3 | #include "EventListenersInterface.h" 4 | #include "EventTypes.h" 5 | #include 6 | class ButtonClickListener : public EventListenersInterface{ 7 | public: 8 | void onEvent(const EventClassesInterface& event) override 9 | { 10 | if(event.getType() == UIEventType::BUTTON_CLICKED) 11 | { 12 | std::cout << "Button clicked!" << std::endl; 13 | } 14 | } 15 | }; 16 | 17 | class TextChangedListener : public EventListenersInterface{ 18 | public: 19 | void onEvent(const EventClassesInterface& event) override 20 | { 21 | if(event.getType() == UIEventType::TEXT_CHANGED) 22 | { 23 | std::cout << "Text is changed!" << std::endl; 24 | } 25 | } 26 | }; 27 | 28 | class DropDownChangedListener : public EventListenersInterface{ 29 | public: 30 | void onEvent(const EventClassesInterface& event) override 31 | { 32 | if(event.getType() == UIEventType::DROPDOWN_CHANGED) 33 | { 34 | std::cout << "DropDown is changed!" << std::endl; 35 | } 36 | } 37 | }; 38 | #endif -------------------------------------------------------------------------------- /60-EventBaseExample/EventListenersInterface.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTLISTENERSINTERFACE_H 2 | #define EVENTLISTENERSINTERFACE_H 3 | #include "EventClassesInterface.h" 4 | class EventListenersInterface{ 5 | public: 6 | virtual ~EventListenersInterface() = default; 7 | virtual void onEvent(const EventClassesInterface& event) = 0; 8 | }; 9 | #endif -------------------------------------------------------------------------------- /60-EventBaseExample/EventTypes.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTTYPES_H 2 | #define EVENTTYPES_H 3 | 4 | enum class UIEventType{ 5 | BUTTON_CLICKED, 6 | TEXT_CHANGED, 7 | CHECKBOX_CHANGED, 8 | RADIO_BUTTON_CHANGED, 9 | DROPDOWN_CHANGED, 10 | SLIDER_CHANGED, 11 | TEXTBOX_CHANGED, 12 | WINDOW_CLOSED, 13 | WINDOW_OPENED, 14 | WINDOW_RESIZED, 15 | WINDOW_MOVED, 16 | WINDOW_MINIMIZED, 17 | WINDOW_MAXIMIZED, 18 | }; 19 | 20 | #endif -------------------------------------------------------------------------------- /60-EventBaseExample/main.cpp: -------------------------------------------------------------------------------- 1 | // Author: Burak Doğançay 2 | #include "EventClasses.h" 3 | #include "EventListeners.h" 4 | #include "EventDispatcher.h" 5 | 6 | int main(int argc, char **argv) 7 | { 8 | EventDispatcher dispatcher; 9 | 10 | //Creating Listeners 11 | std::shared_ptr buttonListener = std::make_shared(); 12 | std::shared_ptr textListener = std::make_shared(); 13 | 14 | //Rgeistering Listeners 15 | dispatcher.addListener(buttonListener); 16 | dispatcher.addListener(textListener); 17 | 18 | //simulate Events 19 | ButtonClickedEvent buttonEvent; 20 | TextChangedEvent textEvent; 21 | TextChangedEvent textEvent2; 22 | 23 | dispatcher.dispatch(buttonEvent); 24 | dispatcher.dispatch(textEvent); 25 | 26 | } -------------------------------------------------------------------------------- /60-EventBaseExample/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esconda/Cpp_Tutorials/99750c39534b97f01e07868f669e415697e2148d/60-EventBaseExample/main.exe -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | It was created and presented for all individuals who want to learn C++ A-Z. 3 | ### Features 4 | - It will contain all the components in C++; 5 | - Some of the importantant libraries will be added like database, Json, xml etc 6 | - Supported by brief explanations; 7 | - Proceeding with practical examples; 8 | - Supported by different approaches; 9 | ### Tools 10 | - Visual Studio Code is used as an IDE; 11 | - MinGW gcc tool chain is used as a compiler; 12 | - Settings are available in .vscode/launch file 13 | - Cpp standard is set as Cpp20 14 | 15 | ### Test 16 | --------------------------------------------------------------------------------