├── .gitignore
├── LICENSE
├── README.md
├── Section 02
├── BasicIO
│ ├── BasicIO.sln
│ └── BasicIO
│ │ ├── BasicIO.vcxproj
│ │ ├── BasicIO.vcxproj.filters
│ │ └── Source.cpp
├── Default Function Args
│ └── DefaultFunctionArgs
│ │ ├── DefaultFunctionArgs.sln
│ │ └── DefaultFunctionArgs
│ │ ├── DefaultFunctionArgs.vcxproj
│ │ ├── DefaultFunctionArgs.vcxproj.filters
│ │ └── Source.cpp
├── First Program
│ ├── First Program.sln
│ └── First Program
│ │ ├── First Program.vcxproj
│ │ ├── First Program.vcxproj.filters
│ │ ├── First Program.vcxproj.user
│ │ └── main.cpp
├── Function Overloading
│ └── Function Overloading
│ │ ├── Function Overloading.sln
│ │ └── Function Overloading
│ │ ├── Function Overloading.vcxproj
│ │ ├── Function Overloading.vcxproj.filters
│ │ └── Source.cpp
├── Function Pointers
│ └── Function Pointer
│ │ ├── Function Pointer.sln
│ │ └── Function Pointer
│ │ ├── Function Pointer.vcxproj
│ │ ├── Function Pointer.vcxproj.filters
│ │ └── Source.cpp
├── Inline functions
│ └── Inline Functions
│ │ ├── Inline Functions.sln
│ │ └── Inline Functions
│ │ ├── Inline Functions.vcxproj
│ │ ├── Inline Functions.vcxproj.filters
│ │ └── Source.cpp
├── Namespace
│ └── Namespace
│ │ ├── Namespace.sln
│ │ └── Namespace
│ │ ├── Namespace.vcxproj
│ │ ├── Namespace.vcxproj.filters
│ │ └── Source.cpp
├── Pointers
│ └── Pointers
│ │ ├── Pointers.sln
│ │ └── Pointers
│ │ ├── Pointers.vcxproj
│ │ ├── Pointers.vcxproj.filters
│ │ ├── Pointers.vcxproj.user
│ │ └── Source.cpp
├── Range-based for
│ └── ForEach
│ │ ├── ForEach.sln
│ │ └── ForEach
│ │ ├── ForEach.vcxproj
│ │ ├── ForEach.vcxproj.filters
│ │ └── Source.cpp
├── Ref Vs Ptr
│ └── SwapFunction
│ │ ├── SwapFunction.sln
│ │ └── SwapFunction
│ │ ├── Source.cpp
│ │ ├── SwapFunction.vcxproj
│ │ └── SwapFunction.vcxproj.filters
├── Reference
│ └── Reference
│ │ ├── Reference.sln
│ │ └── Reference
│ │ ├── Reference.vcxproj
│ │ ├── Reference.vcxproj.filters
│ │ └── Source.cpp
├── auto
│ └── AutoKeyword
│ │ ├── AutoKeyword.sln
│ │ └── AutoKeyword
│ │ ├── AutoKeyword.vcxproj
│ │ ├── AutoKeyword.vcxproj.filters
│ │ └── Source.cpp
└── const Qualifier and Compound Types
│ └── const qualifer
│ ├── const qualifer.sln
│ └── const qualifer
│ ├── Source.cpp
│ ├── const qualifer.vcxproj
│ └── const qualifer.vcxproj.filters
├── Section 03
└── MemMgmtC
│ ├── MemMgmtC.sln
│ └── MemMgmtC
│ ├── MemMgmtC.vcxproj
│ ├── MemMgmtC.vcxproj.filters
│ └── main.cpp
├── Section 04
├── Copy Ctor
│ ├── Copy Ctor.sln
│ └── Copy Ctor
│ │ ├── Copy Ctor.vcxproj
│ │ ├── Copy Ctor.vcxproj.filters
│ │ ├── Integer.cpp
│ │ ├── Integer.h
│ │ └── main.cpp
├── Default and Deleted Functions
│ └── New Class Keywords
│ │ ├── New Class Keywords.sln
│ │ └── New Class Keywords
│ │ ├── New Class Keywords.vcxproj
│ │ ├── New Class Keywords.vcxproj.filters
│ │ └── main.cpp
├── Lvalues and rvalues
│ └── RValues
│ │ ├── RValues.sln
│ │ └── RValues
│ │ ├── RValues.vcxproj
│ │ ├── RValues.vcxproj.filters
│ │ └── Source.cpp
├── Move Semantics Impl
│ └── Copy Ctor - Complete
│ │ ├── Copy Ctor.sln
│ │ └── Copy Ctor
│ │ ├── Copy Ctor.vcxproj
│ │ ├── Copy Ctor.vcxproj.filters
│ │ ├── Integer.cpp
│ │ ├── Integer.h
│ │ └── main.cpp
├── RuleofFive
│ ├── RuleofFive.sln
│ └── RuleofFive
│ │ ├── Integer.cpp
│ │ ├── Integer.h
│ │ ├── RuleofFive.vcxproj
│ │ ├── RuleofFive.vcxproj.filters
│ │ ├── RuleofFive.vcxproj.user
│ │ └── main.cpp
├── Static
│ └── Car Abstraction
│ │ ├── Car Abstraction.sln
│ │ ├── Car Abstraction
│ │ ├── Car Abstraction.vcxproj
│ │ ├── Car Abstraction.vcxproj.filters
│ │ ├── Car.cpp
│ │ ├── Car.h
│ │ └── main.cpp
│ │ └── backup
│ │ ├── Car.cpp
│ │ ├── Car.h
│ │ └── main.cpp
├── class
│ └── Car
│ │ ├── Car.sln
│ │ └── Car
│ │ ├── Car.cpp
│ │ ├── Car.h
│ │ ├── Car.vcxproj
│ │ ├── Car.vcxproj.filters
│ │ └── main.cpp
└── structure
│ └── Structure
│ ├── Structure.sln
│ └── Structure
│ ├── Source.cpp
│ ├── Structure.vcxproj
│ └── Structure.vcxproj.filters
├── Section 05
├── Lvalues and rvalues
│ └── RValues
│ │ ├── RValues.sln
│ │ └── RValues
│ │ ├── RValues.vcxproj
│ │ ├── RValues.vcxproj.filters
│ │ └── Source.cpp
├── Move Semantics Impl
│ └── Copy Ctor - Complete
│ │ ├── Copy Ctor.sln
│ │ └── Copy Ctor
│ │ ├── Copy Ctor.vcxproj
│ │ ├── Copy Ctor.vcxproj.filters
│ │ ├── Integer.cpp
│ │ ├── Integer.h
│ │ └── main.cpp
└── RuleofFive
│ ├── RuleofFive.sln
│ └── RuleofFive
│ ├── Integer.cpp
│ ├── Integer.h
│ ├── RuleofFive.vcxproj
│ ├── RuleofFive.vcxproj.filters
│ └── main.cpp
├── Section 06
├── Operator Overloading
│ ├── Copy Ctor.sln
│ └── Copy Ctor
│ │ ├── Copy Ctor.vcxproj
│ │ ├── Copy Ctor.vcxproj.filters
│ │ ├── Integer.cpp
│ │ ├── Integer.h
│ │ └── main.cpp
└── UserDefConversions
│ ├── UserDefConversions.sln
│ └── UserDefConversions
│ ├── Integer.cpp
│ ├── Integer.h
│ ├── UserDefConversions.vcxproj
│ ├── UserDefConversions.vcxproj.filters
│ ├── UserDefConversions.vcxproj.user
│ └── main.cpp
├── Section 07
├── CircularRef
│ ├── CircularRef.sln
│ └── CircularRef
│ │ ├── CircularRef.vcxproj
│ │ ├── CircularRef.vcxproj.filters
│ │ └── Source.cpp
├── More Features
│ ├── More Features.sln
│ └── More Features
│ │ ├── More Features.vcxproj
│ │ ├── More Features.vcxproj.filters
│ │ └── Source.cpp
├── shared_ptr
│ ├── shared_ptr.sln
│ └── shared_ptr
│ │ ├── Integer.cpp
│ │ ├── Integer.h
│ │ ├── Source.cpp
│ │ ├── shared_ptr.vcxproj
│ │ └── shared_ptr.vcxproj.filters
├── unique_ptr
│ ├── unique_ptr.sln
│ └── unique_ptr
│ │ ├── Integer.cpp
│ │ ├── Integer.h
│ │ ├── Source.cpp
│ │ ├── unique_ptr.vcxproj
│ │ └── unique_ptr.vcxproj.filters
└── weak_ptr
│ ├── weak_ptr.sln
│ └── weak_ptr
│ ├── Source.cpp
│ ├── weak_ptr.vcxproj
│ └── weak_ptr.vcxproj.filters
├── Section 08
├── StringStreams
│ ├── StringStreams.sln
│ └── StringStreams
│ │ ├── Source.cpp
│ │ ├── StringStreams.vcxproj
│ │ └── StringStreams.vcxproj.filters
├── Strings
│ ├── Strings.sln
│ └── Strings
│ │ ├── Source.cpp
│ │ ├── Strings.vcxproj
│ │ └── Strings.vcxproj.filters
├── UserDefinedLiterals
│ ├── UserDefinedLiterals.sln
│ └── UserDefinedLiterals
│ │ ├── Source.cpp
│ │ ├── UserDefinedLiterals.vcxproj
│ │ └── UserDefinedLiterals.vcxproj.filters
├── Vector
│ ├── Vector.sln
│ └── Vector
│ │ ├── Source.cpp
│ │ ├── Vector.vcxproj
│ │ └── Vector.vcxproj.filters
├── constexpr
│ └── constexpr
│ │ ├── constexpr.sln
│ │ └── constexpr
│ │ ├── Source.cpp
│ │ ├── constexpr.vcxproj
│ │ └── constexpr.vcxproj.filters
├── enums
│ ├── enums.sln
│ └── enums
│ │ ├── Source.cpp
│ │ ├── enums.vcxproj
│ │ └── enums.vcxproj.filters
├── initializer_list
│ └── InitializerList
│ │ ├── InitializerList.sln
│ │ └── InitializerList
│ │ ├── InitializerList.vcxproj
│ │ ├── InitializerList.vcxproj.filters
│ │ └── Source.cpp
└── union.cpp
├── Section 09
└── Account
│ ├── Account.sln
│ └── Account
│ ├── Account.cpp
│ ├── Account.h
│ ├── Account.vcxproj
│ ├── Account.vcxproj.filters
│ ├── Checking.cpp
│ ├── Checking.h
│ ├── Savings.cpp
│ ├── Savings.h
│ ├── Transaction.cpp
│ ├── Transaction.h
│ └── main.cpp
├── Section 10
├── ExceptionHandling-noexcept
│ ├── ExceptionHandling-noexcept.sln
│ └── ExceptionHandling-noexcept
│ │ ├── ExceptionHandling-noexcept.vcxproj
│ │ ├── ExceptionHandling-noexcept.vcxproj.filters
│ │ └── Source.cpp
├── Exceptions in ctors
│ └── ExceptionHandlingII
│ │ ├── ExceptionHandlingII.sln
│ │ └── ExceptionHandlingII
│ │ ├── ExceptionHandlingII.vcxproj
│ │ ├── ExceptionHandlingII.vcxproj.filters
│ │ └── Source.cpp
└── Nested Exceptions
│ └── Exception Handling
│ ├── Exception Handling.sln
│ └── Exception Handling
│ ├── Exception Handling.vcxproj
│ ├── Exception Handling.vcxproj.filters
│ └── Source.cpp
├── Section 11
├── Binary Files
│ └── FileIO-BinaryFiles
│ │ ├── FileIO-BinaryFiles.sln
│ │ └── FileIO-BinaryFiles
│ │ ├── FileIO-BinaryFiles.vcxproj
│ │ ├── FileIO-BinaryFiles.vcxproj.filters
│ │ ├── Source.cpp
│ │ ├── binary
│ │ ├── binary.bin
│ │ ├── data
│ │ ├── data.bin
│ │ └── records.bin
└── Error Handling
│ └── File IO
│ └── File IO
│ ├── ClassDiagram.cd
│ ├── File IO.vcxproj
│ ├── File IO.vcxproj.filters
│ ├── Header.h
│ ├── Source.cpp
│ └── data.txt
├── Section 12.5
├── Binder
│ ├── Binder.sln
│ └── Binder
│ │ ├── Binder.vcxproj
│ │ ├── Binder.vcxproj.filters
│ │ ├── Binder.vcxproj.user
│ │ └── main.cpp
└── Function
│ ├── Function.sln
│ └── Function
│ ├── Function.vcxproj
│ ├── Function.vcxproj.filters
│ ├── Function.vcxproj.user
│ └── main.cpp
├── Section 12
├── Aliases
│ └── Aliases
│ │ ├── Aliases.sln
│ │ └── Aliases
│ │ ├── Aliases.vcxproj
│ │ ├── Aliases.vcxproj.filters
│ │ └── Source.cpp
├── Basics
│ ├── Basics.sln
│ └── Basics
│ │ ├── Basics.vcxproj
│ │ ├── Basics.vcxproj.filters
│ │ └── Source.cpp
├── Class Exp Spec - II
│ └── Class Template ExSpecialization
│ │ ├── Class Template ExSpecialization.sln
│ │ └── Class Template ExSpecialization
│ │ ├── Class Template ExSpecialization.vcxproj
│ │ ├── Class Template ExSpecialization.vcxproj.filters
│ │ └── Source.cpp
├── Class Templates
│ └── Class Templates
│ │ ├── Class Templates.sln
│ │ └── Class Templates
│ │ ├── Class Templates.vcxproj
│ │ ├── Class Templates.vcxproj.filters
│ │ └── Source.cpp
├── Partial Spec
│ └── Class Template ParSpecializatoin
│ │ ├── Class Template ParSpecializatoin.sln
│ │ └── Class Template ParSpecializatoin
│ │ ├── Class Template ParSpecializatoin.vcxproj
│ │ ├── Class Template ParSpecializatoin.vcxproj.filters
│ │ └── Source.cpp
├── Perfect Forwarding - II
│ └── Perfect forwarding
│ │ ├── Perfect forwarding.sln
│ │ └── Perfect forwarding
│ │ ├── Integer.cpp
│ │ ├── Integer.h
│ │ ├── Perfect forwarding.vcxproj
│ │ ├── Perfect forwarding.vcxproj.filters
│ │ └── main.cpp
├── StaticAssert
│ └── static_assert.cpp
├── TypeTraits
│ └── traits.cpp
└── Variadic Templates - II
│ └── Variadic Templates
│ ├── Variadic Templates.sln
│ └── Variadic Templates
│ ├── Integer.cpp
│ ├── Integer.h
│ ├── Source.cpp
│ ├── Variadic Templates.vcxproj
│ └── Variadic Templates.vcxproj.filters
├── Section 13
├── Capture List
│ └── CaptureList
│ │ ├── CaptureList.sln
│ │ └── CaptureList
│ │ ├── CaptureList.vcxproj
│ │ ├── CaptureList.vcxproj.filters
│ │ └── Source.cpp
├── Function Objects
│ └── Function Objects
│ │ ├── Function Objects.sln
│ │ └── Function Objects
│ │ ├── Function Objects.vcxproj
│ │ ├── Function Objects.vcxproj.filters
│ │ └── Source.cpp
└── Lambda Basics
│ └── Lambda Basics
│ ├── Lambda Basics.sln
│ └── Lambda Basics
│ ├── Lambda Basics.vcxproj
│ ├── Lambda Basics.vcxproj.filters
│ └── Source.cpp
├── Section 14
└── STL
│ ├── Algorithms.zip
│ ├── Algorithms
│ ├── Algorithms.sln
│ └── Algorithms
│ │ ├── Algorithms.vcxproj
│ │ ├── Algorithms.vcxproj.filters
│ │ └── Source.cpp
│ ├── AssociativeContainers.zip
│ ├── AssociativeContainers
│ ├── AssociativeContainers.sln
│ └── AssociativeContainers
│ │ ├── AssociativeContainers.vcxproj
│ │ ├── AssociativeContainers.vcxproj.filters
│ │ └── Source.cpp
│ ├── ContainerChanges
│ ├── ContainerChanges.sln
│ └── ContainerChanges
│ │ ├── ContainerChanges.vcxproj
│ │ ├── ContainerChanges.vcxproj.filters
│ │ ├── Integer.cpp
│ │ ├── Integer.h
│ │ └── main.cpp
│ ├── SequenceContainers.zip
│ ├── SequenceContainers
│ ├── SequenceContainers.sln
│ └── SequenceContainers
│ │ ├── SequenceContainers.vcxproj
│ │ ├── SequenceContainers.vcxproj.filters
│ │ └── Source.cpp
│ ├── UnorderedContainers.zip
│ └── UnorderedContainers
│ ├── UnorderedContainers.sln
│ └── UnorderedContainers
│ ├── Source.cpp
│ ├── UnorderedContainers.vcxproj
│ └── UnorderedContainers.vcxproj.filters
├── Section 15
├── Async
│ ├── Async.sln
│ └── Async
│ │ ├── Async.vcxproj
│ │ ├── Async.vcxproj.filters
│ │ ├── Source.cpp
│ │ └── main.cpp
├── PromiseFuture
│ ├── PromiseFuture.sln
│ └── PromiseFuture
│ │ ├── PromiseFuture.vcxproj
│ │ ├── PromiseFuture.vcxproj.filters
│ │ └── Source.cpp
├── Sharing Data
│ ├── Sharing Data.sln
│ └── Sharing Data
│ │ ├── Sharing Data.vcxproj
│ │ ├── Sharing Data.vcxproj.filters
│ │ └── Source.cpp
├── ThreadClass
│ ├── ThreadClass.sln
│ └── ThreadClass
│ │ ├── Source.cpp
│ │ ├── ThreadClass.vcxproj
│ │ └── ThreadClass.vcxproj.filters
└── Threads
│ ├── Threads.sln
│ └── Threads
│ ├── Source.cpp
│ ├── Threads.vcxproj
│ └── Threads.vcxproj.filters
├── Section 16
├── attributes
│ └── attributes.cpp
├── constexprlambda
│ └── constexprlambda.cpp
├── evaluationorder
│ └── evaluationorder.cpp
├── featuremacros
│ └── featuremacros.cpp
├── ifswitch
│ └── ifswitch.cpp
├── inline variables
│ ├── a.cpp
│ ├── b.cpp
│ ├── main.cpp
│ └── vars.h
├── mandatorycopyelision
│ └── mandatorycopyelision.cpp
├── nestednamespaces
│ └── nestednamespaces.cpp
├── noexcept
│ └── noexcept.cpp
└── structuredbindings
│ └── structuredbindings.cpp
├── Section 17
├── CTAD
│ └── CTAD.cpp
├── fold expressions
│ └── fold expressions.cpp
├── ifconstexpr
│ └── ifconstexpr.cpp
└── traitssuffixes
│ └── traitssuffixes.cpp
└── Section 18
├── any
└── any.cpp
├── filesystem
└── filesystem.cpp
├── optional
└── optional.cpp
├── parallel
└── parallel.cpp
├── string view
└── string view.cpp
└── variant
└── variant.cpp
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 umarmlone
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # beg_mod_cpp
2 | Source code of the demos from Complete Modern C++ course.
3 |
--------------------------------------------------------------------------------
/Section 02/BasicIO/BasicIO.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BasicIO", "BasicIO\BasicIO.vcxproj", "{5E9A6FD7-7D07-45A7-A7C6-476DB7355CD1}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {5E9A6FD7-7D07-45A7-A7C6-476DB7355CD1}.Debug|x64.ActiveCfg = Debug|x64
17 | {5E9A6FD7-7D07-45A7-A7C6-476DB7355CD1}.Debug|x64.Build.0 = Debug|x64
18 | {5E9A6FD7-7D07-45A7-A7C6-476DB7355CD1}.Debug|x86.ActiveCfg = Debug|Win32
19 | {5E9A6FD7-7D07-45A7-A7C6-476DB7355CD1}.Debug|x86.Build.0 = Debug|Win32
20 | {5E9A6FD7-7D07-45A7-A7C6-476DB7355CD1}.Release|x64.ActiveCfg = Release|x64
21 | {5E9A6FD7-7D07-45A7-A7C6-476DB7355CD1}.Release|x64.Build.0 = Release|x64
22 | {5E9A6FD7-7D07-45A7-A7C6-476DB7355CD1}.Release|x86.ActiveCfg = Release|Win32
23 | {5E9A6FD7-7D07-45A7-A7C6-476DB7355CD1}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 02/BasicIO/BasicIO/BasicIO.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 02/BasicIO/BasicIO/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | using namespace std;
5 |
6 | char buff[512];
7 | cout << "What is your name?";
8 | /*
9 | There's a better way to do it. Check the
10 | lecture on std::strings if you're curious :)
11 | */
12 | cin.getline(buff, 64, '\n');
13 | cout << "Your name is:" << buff << endl;
14 |
15 | int age ;
16 | cin >> age ;
17 | return 0;
18 | }
--------------------------------------------------------------------------------
/Section 02/Default Function Args/DefaultFunctionArgs/DefaultFunctionArgs/DefaultFunctionArgs.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 02/Default Function Args/DefaultFunctionArgs/DefaultFunctionArgs/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | void CreateWindow(const char * title, int x, int y, int width, int height);
3 |
4 |
5 | void CreateWindow(const char * title, int x = -1, int y = -1, int width = -1, int height = -1) {
6 | using namespace std;
7 | cout << "Title : " << title << endl;
8 | cout << "x : " << x << endl;
9 | cout << "y : " << y << endl;
10 | cout << "Width : " << width << endl;
11 | cout << "Height : " << height << endl;
12 | }
13 | int main() {
14 | /*
15 | Not all arguments are necessary. If you specify arguments,
16 | they should be specified from right to left.
17 | */
18 | CreateWindow("Notepad", 100, 200);
19 | return 0;
20 | }
--------------------------------------------------------------------------------
/Section 02/First Program/First Program.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "First Program", "First Program\First Program.vcxproj", "{E2A42C46-C7A6-4202-918F-D4541745C27A}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {E2A42C46-C7A6-4202-918F-D4541745C27A}.Debug|x64.ActiveCfg = Debug|x64
17 | {E2A42C46-C7A6-4202-918F-D4541745C27A}.Debug|x64.Build.0 = Debug|x64
18 | {E2A42C46-C7A6-4202-918F-D4541745C27A}.Debug|x86.ActiveCfg = Debug|Win32
19 | {E2A42C46-C7A6-4202-918F-D4541745C27A}.Debug|x86.Build.0 = Debug|Win32
20 | {E2A42C46-C7A6-4202-918F-D4541745C27A}.Release|x64.ActiveCfg = Release|x64
21 | {E2A42C46-C7A6-4202-918F-D4541745C27A}.Release|x64.Build.0 = Release|x64
22 | {E2A42C46-C7A6-4202-918F-D4541745C27A}.Release|x86.ActiveCfg = Release|Win32
23 | {E2A42C46-C7A6-4202-918F-D4541745C27A}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 02/First Program/First Program/First Program.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 02/First Program/First Program/First Program.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Section 02/First Program/First Program/main.cpp:
--------------------------------------------------------------------------------
1 | //This is a single line comment
2 |
3 | /*
4 | This is a
5 | multi line comment
6 | */
7 |
8 |
9 | #include
10 | #include
11 | enum e1{} ;
12 | enum class e2{};
13 |
14 | int main() {
15 | bool e1_type = std::is_same<
16 | int
17 | ,typename std::underlying_type::type
18 | >::value;
19 |
20 | bool e2_type = std::is_same<
21 | int
22 | ,typename std::underlying_type::type
23 | >::value;
24 |
25 | std::cout
26 | << "underlying type for 'e1' is " << (e1_type?"int":"non-int") << '\n'
27 | << "underlying type for 'e2' is " << (e2_type?"int":"non-int") << '\n';
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/Section 02/Function Overloading/Function Overloading/Function Overloading/Function Overloading.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 02/Function Overloading/Function Overloading/Function Overloading/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | int Add(int a, int b) {
3 | return a + b;
4 | }
5 | double Add(double a, double b) {
6 | return a + b;
7 | }
8 | extern "C" void Print(int *x) {
9 |
10 | }
11 | void Print(const int* x) {
12 |
13 | }
14 | int main() {
15 | using namespace std;
16 | int result = Add(3, 5);
17 | cout << result << endl;
18 | Add(3.1, 6.2);
19 | const int x = 1;
20 | Print(&x);
21 | return 0;
22 | }
--------------------------------------------------------------------------------
/Section 02/Function Pointers/Function Pointer/Function Pointer/Function Pointer.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 02/Function Pointers/Function Pointer/Function Pointer/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | void Print(int count, char ch) {
3 | using namespace std;
4 | for (int i = 0; i < count; ++i) {
5 | cout << ch;
6 | }
7 | cout << endl;
8 | }
9 | void EndMessage() {
10 | using namespace std;
11 | cout << "End of program" << endl;
12 | }
13 | int main() {
14 | //Register a handler. This handler will be invoked after main returns
15 | atexit(EndMessage);
16 | Print(5, '#');
17 | void(*pfn) (int, char) = Print;
18 | //One way to invoke function pointer
19 | (*pfn)(8, '@');
20 | //Another way to invoke function pointer
21 | pfn(5, '+');
22 | using namespace std;
23 | cout << "end of main" << endl;
24 | return 0;
25 | }
--------------------------------------------------------------------------------
/Section 02/Inline functions/Inline Functions/Inline Functions/Inline Functions.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 02/Inline functions/Inline Functions/Inline Functions/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | inline int Square(int x) {
3 | return x * x;
4 | }
5 | //#define Square(x) x*x
6 | int main() {
7 | using namespace std;
8 | int val = 5;
9 | int result = Square(val + 1);
10 | cout << result << endl;
11 | return 0;
12 | }
--------------------------------------------------------------------------------
/Section 02/Namespace/Namespace/Namespace.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Namespace", "Namespace\Namespace.vcxproj", "{C04275D4-A275-4E65-8BC9-1C195DE1C14D}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {C04275D4-A275-4E65-8BC9-1C195DE1C14D}.Debug|x64.ActiveCfg = Debug|x64
17 | {C04275D4-A275-4E65-8BC9-1C195DE1C14D}.Debug|x64.Build.0 = Debug|x64
18 | {C04275D4-A275-4E65-8BC9-1C195DE1C14D}.Debug|x86.ActiveCfg = Debug|Win32
19 | {C04275D4-A275-4E65-8BC9-1C195DE1C14D}.Debug|x86.Build.0 = Debug|Win32
20 | {C04275D4-A275-4E65-8BC9-1C195DE1C14D}.Release|x64.ActiveCfg = Release|x64
21 | {C04275D4-A275-4E65-8BC9-1C195DE1C14D}.Release|x64.Build.0 = Release|x64
22 | {C04275D4-A275-4E65-8BC9-1C195DE1C14D}.Release|x86.ActiveCfg = Release|Win32
23 | {C04275D4-A275-4E65-8BC9-1C195DE1C14D}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 02/Namespace/Namespace/Namespace/Namespace.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 02/Namespace/Namespace/Namespace/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | namespace Avg {
4 | float Calculate(float x, float y) {
5 | return (x + y) / 2;
6 | }
7 | }
8 |
9 | namespace Basic {
10 | float Calculate(float x, float y) {
11 | return x + y;
12 | }
13 | }
14 | namespace Sort {
15 | void Quicksort() {
16 |
17 | }
18 | void Insertionsort() {
19 |
20 | }
21 | void Mergesort() {
22 |
23 | }
24 | namespace Comparision {
25 | void Less() {
26 |
27 | }
28 | void Greater() {
29 |
30 | }
31 | }
32 | }
33 | namespace {
34 | void InternalFunction() {
35 |
36 | }
37 | }
38 | int main() {
39 | //Avoid opening a namespace at a global scope
40 |
41 | InternalFunction();
42 | using namespace Sort::Comparision;
43 | Sort::Comparision::Less();
44 | return 0;
45 | }
--------------------------------------------------------------------------------
/Section 02/Pointers/Pointers/Pointers.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Pointers", "Pointers\Pointers.vcxproj", "{E1B9DEFE-F4DB-4417-85C8-C0A95B919C8B}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {E1B9DEFE-F4DB-4417-85C8-C0A95B919C8B}.Debug|x64.ActiveCfg = Debug|x64
17 | {E1B9DEFE-F4DB-4417-85C8-C0A95B919C8B}.Debug|x64.Build.0 = Debug|x64
18 | {E1B9DEFE-F4DB-4417-85C8-C0A95B919C8B}.Debug|x86.ActiveCfg = Debug|Win32
19 | {E1B9DEFE-F4DB-4417-85C8-C0A95B919C8B}.Debug|x86.Build.0 = Debug|Win32
20 | {E1B9DEFE-F4DB-4417-85C8-C0A95B919C8B}.Release|x64.ActiveCfg = Release|x64
21 | {E1B9DEFE-F4DB-4417-85C8-C0A95B919C8B}.Release|x64.Build.0 = Release|x64
22 | {E1B9DEFE-F4DB-4417-85C8-C0A95B919C8B}.Release|x86.ActiveCfg = Release|Win32
23 | {E1B9DEFE-F4DB-4417-85C8-C0A95B919C8B}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 02/Pointers/Pointers/Pointers/Pointers.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 02/Pointers/Pointers/Pointers/Pointers.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Section 02/Pointers/Pointers/Pointers/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | using namespace std;
5 | int x = 10;
6 | cout << &x << "\n";
7 | int *ptr = nullptr;
8 | //cout << *ptr << "\n";
9 | *ptr = 10 ;
10 | return 0;
11 | }
--------------------------------------------------------------------------------
/Section 02/Range-based for/ForEach/ForEach.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ForEach", "ForEach\ForEach.vcxproj", "{5A55E07E-4228-4765-AC39-829FDCE99715}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {5A55E07E-4228-4765-AC39-829FDCE99715}.Debug|x64.ActiveCfg = Debug|x64
17 | {5A55E07E-4228-4765-AC39-829FDCE99715}.Debug|x64.Build.0 = Debug|x64
18 | {5A55E07E-4228-4765-AC39-829FDCE99715}.Debug|x86.ActiveCfg = Debug|Win32
19 | {5A55E07E-4228-4765-AC39-829FDCE99715}.Debug|x86.Build.0 = Debug|Win32
20 | {5A55E07E-4228-4765-AC39-829FDCE99715}.Release|x64.ActiveCfg = Release|x64
21 | {5A55E07E-4228-4765-AC39-829FDCE99715}.Release|x64.Build.0 = Release|x64
22 | {5A55E07E-4228-4765-AC39-829FDCE99715}.Release|x86.ActiveCfg = Release|Win32
23 | {5A55E07E-4228-4765-AC39-829FDCE99715}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 02/Range-based for/ForEach/ForEach/ForEach.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 02/Range-based for/ForEach/ForEach/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | int main() {
3 | using namespace std;
4 | int arr[] = { 1,2,3,4,5 };
5 | for (int i = 0; i < 5; i++) {
6 | cout << arr[i] << " ";
7 | }
8 | for (const auto & x : arr) {
9 |
10 | cout << x << " ";
11 | }
12 | for (auto x : { 1,2,3,4 }) {
13 | cout << x;
14 | }
15 | return 0;
16 | }
--------------------------------------------------------------------------------
/Section 02/Ref Vs Ptr/SwapFunction/SwapFunction.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SwapFunction", "SwapFunction\SwapFunction.vcxproj", "{B536CB47-A6DA-4607-8083-3743DE0D10A4}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {B536CB47-A6DA-4607-8083-3743DE0D10A4}.Debug|x64.ActiveCfg = Debug|x64
17 | {B536CB47-A6DA-4607-8083-3743DE0D10A4}.Debug|x64.Build.0 = Debug|x64
18 | {B536CB47-A6DA-4607-8083-3743DE0D10A4}.Debug|x86.ActiveCfg = Debug|Win32
19 | {B536CB47-A6DA-4607-8083-3743DE0D10A4}.Debug|x86.Build.0 = Debug|Win32
20 | {B536CB47-A6DA-4607-8083-3743DE0D10A4}.Release|x64.ActiveCfg = Release|x64
21 | {B536CB47-A6DA-4607-8083-3743DE0D10A4}.Release|x64.Build.0 = Release|x64
22 | {B536CB47-A6DA-4607-8083-3743DE0D10A4}.Release|x86.ActiveCfg = Release|Win32
23 | {B536CB47-A6DA-4607-8083-3743DE0D10A4}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 02/Ref Vs Ptr/SwapFunction/SwapFunction/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | /*
3 | Difficult to use and prone to errors
4 | Also needs a null check
5 | */
6 | void Swap(int *x, int *y) {
7 | int temp = *x;
8 | *x = *y;
9 | *y = temp;
10 | }
11 |
12 | //Easy to use and no null check required
13 | void Swap(int &x, int &y) {
14 | int temp = x;
15 | x = y;
16 | y = temp;
17 | }
18 | int main() {
19 | using namespace std;
20 | int a = 5, b = 10;
21 | Swap(a, b);
22 | cout << "a:" << a << "\n";
23 | cout << "b:" << b << "\n";
24 | return 0;
25 | }
--------------------------------------------------------------------------------
/Section 02/Ref Vs Ptr/SwapFunction/SwapFunction/SwapFunction.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 02/Reference/Reference/Reference.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Reference", "Reference\Reference.vcxproj", "{5F6BE421-4599-454F-9F72-CC49BFD24ED4}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {5F6BE421-4599-454F-9F72-CC49BFD24ED4}.Debug|x64.ActiveCfg = Debug|x64
17 | {5F6BE421-4599-454F-9F72-CC49BFD24ED4}.Debug|x64.Build.0 = Debug|x64
18 | {5F6BE421-4599-454F-9F72-CC49BFD24ED4}.Debug|x86.ActiveCfg = Debug|Win32
19 | {5F6BE421-4599-454F-9F72-CC49BFD24ED4}.Debug|x86.Build.0 = Debug|Win32
20 | {5F6BE421-4599-454F-9F72-CC49BFD24ED4}.Release|x64.ActiveCfg = Release|x64
21 | {5F6BE421-4599-454F-9F72-CC49BFD24ED4}.Release|x64.Build.0 = Release|x64
22 | {5F6BE421-4599-454F-9F72-CC49BFD24ED4}.Release|x86.ActiveCfg = Release|Win32
23 | {5F6BE421-4599-454F-9F72-CC49BFD24ED4}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 02/Reference/Reference/Reference/Reference.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 02/Reference/Reference/Reference/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | using namespace std;
5 | //Referent
6 | int x = 10;
7 | //Reference
8 | int &ref = x;
9 | int y = 20;
10 | ref = y;
11 | cout << "x:" << x << endl;
12 | cout << "ref:" << ref << endl;
13 | return 0 ;
14 | }
--------------------------------------------------------------------------------
/Section 02/auto/AutoKeyword/AutoKeyword.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AutoKeyword", "AutoKeyword\AutoKeyword.vcxproj", "{3382D8D0-E6E2-4F4E-818B-CB36D18B0D26}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {3382D8D0-E6E2-4F4E-818B-CB36D18B0D26}.Debug|x64.ActiveCfg = Debug|x64
17 | {3382D8D0-E6E2-4F4E-818B-CB36D18B0D26}.Debug|x64.Build.0 = Debug|x64
18 | {3382D8D0-E6E2-4F4E-818B-CB36D18B0D26}.Debug|x86.ActiveCfg = Debug|Win32
19 | {3382D8D0-E6E2-4F4E-818B-CB36D18B0D26}.Debug|x86.Build.0 = Debug|Win32
20 | {3382D8D0-E6E2-4F4E-818B-CB36D18B0D26}.Release|x64.ActiveCfg = Release|x64
21 | {3382D8D0-E6E2-4F4E-818B-CB36D18B0D26}.Release|x64.Build.0 = Release|x64
22 | {3382D8D0-E6E2-4F4E-818B-CB36D18B0D26}.Release|x86.ActiveCfg = Release|Win32
23 | {3382D8D0-E6E2-4F4E-818B-CB36D18B0D26}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 02/auto/AutoKeyword/AutoKeyword/AutoKeyword.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 02/auto/AutoKeyword/AutoKeyword/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | int Sum(int x, int y) {
3 | return x + y;
4 | }
5 | int main() {
6 | //One of my favorite features of C++11 ;)
7 | auto i = 10;
8 | auto j = 5;
9 | auto sum = i + 4.3f;
10 |
11 | auto result = Sum(i, j);
12 | static auto y = 2;
13 | const int x = 10;
14 | //Works with qualifiers
15 | const auto var = x;
16 | //Deduced to reference
17 | auto &var1 = x;
18 |
19 | //Deduced to a pointer. * is not necessary
20 | auto *ptr = &x;
21 | return 0;
22 | }
--------------------------------------------------------------------------------
/Section 02/const Qualifier and Compound Types/const qualifer/const qualifer/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | void Print(int *ptr) {
3 | using namespace std;
4 | cout << *ptr << endl;
5 | }
6 | void UsingConst() {
7 | using namespace std;
8 | float radius = 0;
9 | cin >> radius;
10 | const float PI = 3.14159f;
11 | float area = PI * radius * radius;
12 | float circumference = PI * 2 * radius;
13 | cout << "Area is : " << area << endl;
14 | cout << "Circumference is : " << circumference << endl;
15 |
16 | const int CHUNK_SIZE = 512;
17 | const int *const ptr = &CHUNK_SIZE;
18 | //*ptr = 1;
19 | int x = 10;
20 | //ptr = &x;
21 | //*ptr = 1;
22 | Print(&x);
23 | cout << "main->x" << x << endl;
24 | }
25 |
26 | void PrintRef(const int &ref) {
27 | using namespace std;
28 | cout << ref << endl;
29 | }
30 | void UsingConstRef() {
31 | int x = 5;
32 | PrintRef(1);
33 | }
34 | int main() {
35 | UsingConst();
36 | UsingConstRef();
37 |
38 | return 0;
39 | }
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/Section 02/const Qualifier and Compound Types/const qualifer/const qualifer/const qualifer.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 03/MemMgmtC/MemMgmtC/MemMgmtC.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 03/MemMgmtC/MemMgmtC/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | void Malloc() {
5 | //int *p = (int*)calloc(5, sizeof(int));
6 | int *p = (int*)malloc(5 * sizeof(int));
7 | if (p == NULL) {
8 | printf("Failed to allocate memory\n");
9 | return;
10 | }
11 | *p = 5;
12 | printf("%d", *p);
13 | //free(p);
14 | p = NULL;
15 | //free(p);
16 | }
17 |
18 | void New() {
19 | int *p = new int(5);
20 | *p = 6;
21 | std::cout << *p << std::endl;
22 | delete p;
23 | p = nullptr;
24 | }
25 | void NewArrays() {
26 | int *p = new int[5];
27 | for (int i = 0; i < 5; ++i) {
28 | p[i] = i;
29 | }
30 | delete[]p;
31 | }
32 | void Strings() {
33 | char *p = new char[4];
34 | strcpy_s(p, 4, "C++");
35 | std::cout << p << std::endl;
36 | delete[]p;
37 | }
38 | void TwoD() {
39 | int *p1 = new int[3];
40 | int *p2 = new int[3];
41 |
42 | int **pData = new int *[2];
43 | pData[0] = p1;
44 | pData[1] = p2;
45 |
46 | pData[0][1] = 2;
47 |
48 | delete[]p1;//delete []pData[0]
49 | delete[]p2;//delete []pData[1]
50 |
51 | delete [] pData;
52 | }
53 | int main() {
54 | int data[2][3] = {
55 | 1,2,3,
56 | 4,5,6
57 | }; //1,2,3,4,5,6
58 | //data[0][1]
59 | Strings();
60 |
61 |
62 |
63 | return 0;
64 | }
--------------------------------------------------------------------------------
/Section 04/Copy Ctor/Copy Ctor.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Copy Ctor", "Copy Ctor\Copy Ctor.vcxproj", "{94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x64.ActiveCfg = Debug|x64
17 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x64.Build.0 = Debug|x64
18 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x86.ActiveCfg = Debug|Win32
19 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x86.Build.0 = Debug|Win32
20 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x64.ActiveCfg = Release|x64
21 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x64.Build.0 = Release|x64
22 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x86.ActiveCfg = Release|Win32
23 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 04/Copy Ctor/Copy Ctor/Copy Ctor.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 |
23 |
24 | Source Files
25 |
26 |
27 | Source Files
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Section 04/Copy Ctor/Copy Ctor/Integer.cpp:
--------------------------------------------------------------------------------
1 | #include "Integer.h"
2 | #include
3 | Integer::Integer() {
4 | std::cout << "Integer()" << std::endl;
5 | m_pInt = new int(0);
6 | }
7 |
8 | Integer::Integer(int value) {
9 | std::cout << "Integer(int)" << std::endl;
10 | m_pInt = new int(value);
11 | }
12 |
13 | Integer::Integer(const Integer & obj) {
14 | std::cout << "Integer(const Integer&)" << std::endl;
15 | m_pInt = new int(*obj.m_pInt);
16 | }
17 |
18 |
19 | int Integer::GetValue() const {
20 | return *m_pInt;
21 | }
22 |
23 | void Integer::SetValue(int value) {
24 | *m_pInt = value;
25 | }
26 |
27 | Integer::~Integer() {
28 | std::cout << "~Integer()" << std::endl;
29 | delete m_pInt;
30 | }
31 |
--------------------------------------------------------------------------------
/Section 04/Copy Ctor/Copy Ctor/Integer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | class Integer {
4 | int *m_pInt;
5 | public:
6 | Integer();
7 | Integer(int value);
8 | Integer(const Integer &obj);
9 | int GetValue()const;
10 | void SetValue(int value);
11 | ~Integer();
12 |
13 | };
14 |
--------------------------------------------------------------------------------
/Section 04/Copy Ctor/Copy Ctor/main.cpp:
--------------------------------------------------------------------------------
1 | #include "Integer.h"
2 | #include
3 | #include
4 | class IntPtr {
5 | Integer *m_p;
6 | public:
7 | IntPtr(Integer *p) :m_p(p) {
8 |
9 | }
10 | ~IntPtr() {
11 | delete m_p;
12 | }
13 | Integer *operator ->() {
14 | return m_p;
15 | }
16 | Integer & operator *() {
17 | return *m_p;
18 | }
19 | };
20 | void CreateInteger() {
21 | std::unique_ptr p(new Integer);
22 | //auto p2(p);
23 | (*p).SetValue(3);
24 | //std::cout << p->GetValue() << std::endl;
25 | }
26 | void Process(Integer val) {
27 |
28 | }
29 |
30 | int main() {
31 | Integer a(3);
32 | /*auto b(std::move(a));
33 | std::cout << a << std::endl;*/
34 | Process(std::move(a));
35 | return 0;
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/Section 04/Default and Deleted Functions/New Class Keywords/New Class Keywords/New Class Keywords.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 04/Default and Deleted Functions/New Class Keywords/New Class Keywords/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | class Integer {
3 | int m_Value{ 0 };
4 | public:
5 | Integer() = default;
6 | //Integer() {
7 | // m_Value = 0;
8 | //}
9 | Integer(int value) {
10 | m_Value = value;
11 | }
12 | Integer(const Integer &) = delete;
13 | void SetValue(int value) {
14 | m_Value = value;
15 | }
16 | void SetValue(float) = delete;
17 | };
18 |
19 | int main() {
20 | Integer i1;
21 | i1.SetValue(5);
22 | //Error as SetValue(float) is deleted
23 | i1.SetValue(67.1f);
24 | return 0;
25 | }
--------------------------------------------------------------------------------
/Section 04/Lvalues and rvalues/RValues/RValues.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RValues", "RValues\RValues.vcxproj", "{0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Debug|x64.ActiveCfg = Debug|x64
17 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Debug|x64.Build.0 = Debug|x64
18 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Debug|x86.ActiveCfg = Debug|Win32
19 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Debug|x86.Build.0 = Debug|Win32
20 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Release|x64.ActiveCfg = Release|x64
21 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Release|x64.Build.0 = Release|x64
22 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Release|x86.ActiveCfg = Release|Win32
23 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 04/Lvalues and rvalues/RValues/RValues/RValues.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 04/Lvalues and rvalues/RValues/RValues/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | //Returns r-value
4 | int Add(int x, int y) {
5 | return x + y;
6 | }
7 | //Return l-value
8 | int & Transform(int &x) {
9 | x *= x;
10 | return x;
11 | }
12 |
13 | void Print(int &x) {
14 | std::cout << "Print(int&)" << std::endl;
15 | }
16 | void Print(const int &x) {
17 | std::cout << "Print(const int&)" << std::endl;
18 |
19 | }
20 | void Print(int &&x) {
21 | std::cout << "Print(int &&)" << std::endl;
22 | }
23 | int main() {
24 | //x is lvalue
25 | int x = 10;
26 |
27 | //ref is l-value reference
28 | int &ref = x ;
29 | //Transform returns an l-value
30 | int &ref2 = Transform(x) ;
31 | //Binds to function that accepts l-value reference
32 | Print(x);
33 |
34 |
35 | //rv is r-value reference
36 | int &&rv = 8 ;
37 |
38 | //Add returns a temporary (r-value)
39 | int &&rv2 = Add(3,5) ;
40 | //Binds to function that accepts a temporary, i.e. r-value reference
41 | Print(3);
42 | return 0;
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/Section 04/Move Semantics Impl/Copy Ctor - Complete/Copy Ctor.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Copy Ctor", "Copy Ctor\Copy Ctor.vcxproj", "{94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x64.ActiveCfg = Debug|x64
17 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x64.Build.0 = Debug|x64
18 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x86.ActiveCfg = Debug|Win32
19 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x86.Build.0 = Debug|Win32
20 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x64.ActiveCfg = Release|x64
21 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x64.Build.0 = Release|x64
22 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x86.ActiveCfg = Release|Win32
23 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 04/Move Semantics Impl/Copy Ctor - Complete/Copy Ctor/Copy Ctor.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 |
23 |
24 | Source Files
25 |
26 |
27 | Source Files
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Section 04/Move Semantics Impl/Copy Ctor - Complete/Copy Ctor/Integer.cpp:
--------------------------------------------------------------------------------
1 | #include "Integer.h"
2 | #include
3 | Integer::Integer() {
4 | std::cout << "Integer()" << std::endl;
5 | m_pInt = new int(0);
6 | }
7 |
8 | Integer::Integer(int value) {
9 | std::cout << "Integer(int)" << std::endl;
10 | m_pInt = new int(value);
11 | }
12 |
13 | Integer::Integer(const Integer & obj) {
14 | std::cout << "Integer(const Integer&)" << std::endl;
15 | m_pInt = new int(*obj.m_pInt);
16 | }
17 |
18 | Integer::Integer(Integer && obj) {
19 | std::cout << "Integer(int&&)" << std::endl;
20 | m_pInt = obj.m_pInt;
21 | obj.m_pInt = nullptr;
22 | }
23 |
24 | int Integer::GetValue() const {
25 | return *m_pInt;
26 | }
27 |
28 | void Integer::SetValue(int value) {
29 | *m_pInt = value;
30 | }
31 |
32 | Integer::~Integer() {
33 | std::cout << "~Integer()" << std::endl;
34 | delete m_pInt;
35 | }
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/Section 04/Move Semantics Impl/Copy Ctor - Complete/Copy Ctor/Integer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | class Integer {
4 | int *m_pInt;
5 | public:
6 | //Default constructor
7 | Integer();
8 | //Parameterized constructor
9 | Integer(int value);
10 | //Copy constructor
11 | Integer(const Integer &obj);
12 | //Move constructor
13 | Integer(Integer &&obj);
14 | int GetValue()const;
15 | void SetValue(int value);
16 | ~Integer();
17 |
18 | };
19 |
--------------------------------------------------------------------------------
/Section 04/Move Semantics Impl/Copy Ctor - Complete/Copy Ctor/main.cpp:
--------------------------------------------------------------------------------
1 | #include "Integer.h"
2 | #include
3 |
4 | Integer Add(const Integer &a, const Integer &b){
5 | Integer temp ;
6 | temp.SetValue(a.GetValue() + b.GetValue()) ;
7 | }
8 | int main() {
9 | Integer a(1), b(3) ;
10 | a.SetValue(Add(a,b).GetValue()) ;
11 |
12 |
13 | return 0;
14 | }
--------------------------------------------------------------------------------
/Section 04/RuleofFive/RuleofFive/Integer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | class Integer {
4 | int *m_pInt;
5 | public:
6 | //Default constructor
7 | Integer();
8 |
9 | //Parameterized constructor
10 | Integer(int value);
11 |
12 | //Copy constructor
13 | Integer(const Integer &obj);
14 |
15 | //Move constructor
16 | Integer(Integer &&obj);
17 |
18 | //Copy assignment
19 | Integer & operator=(const Integer &obj) ;
20 |
21 | //Move assignment
22 | Integer & operator=(Integer && obj) ;
23 |
24 | int GetValue()const;
25 | void SetValue(int value);
26 | ~Integer();
27 |
28 | };
29 |
--------------------------------------------------------------------------------
/Section 04/RuleofFive/RuleofFive/RuleofFive.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 |
26 |
27 | Header Files
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Section 04/RuleofFive/RuleofFive/RuleofFive.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Section 04/RuleofFive/RuleofFive/main.cpp:
--------------------------------------------------------------------------------
1 | #include "Integer.h"
2 | class Number{
3 | Integer m_Value{} ;
4 | public:
5 | Number()=default ;
6 | Number(int value):m_Value{value}{
7 | }
8 | /*Number(const Number &n):m_Value{n.m_Value}{
9 | }*/
10 | /*~Number(){
11 | }*/
12 | Number(Number &&n) = default ;
13 | Number(const Number &n) = default ;
14 | Number & operator=(Number&&)=default ;
15 | Number & operator=(const Number&)=default ;
16 | };
17 | Number CreateNumber(int num){
18 | Number n{num} ;
19 | return n ;
20 | }
21 | int main(){
22 | Number n1 ;
23 | auto n2{n1} ;
24 | n2 = n1 ;
25 |
26 | auto n3{CreateNumber(3)} ;
27 | n3 = CreateNumber(3) ;
28 | }
29 |
--------------------------------------------------------------------------------
/Section 04/Static/Car Abstraction/Car Abstraction.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Car Abstraction", "Car Abstraction\Car Abstraction.vcxproj", "{F121FD3F-B62E-4F0A-9BC5-84606D6CA2D5}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {F121FD3F-B62E-4F0A-9BC5-84606D6CA2D5}.Debug|x64.ActiveCfg = Debug|x64
17 | {F121FD3F-B62E-4F0A-9BC5-84606D6CA2D5}.Debug|x64.Build.0 = Debug|x64
18 | {F121FD3F-B62E-4F0A-9BC5-84606D6CA2D5}.Debug|x86.ActiveCfg = Debug|Win32
19 | {F121FD3F-B62E-4F0A-9BC5-84606D6CA2D5}.Debug|x86.Build.0 = Debug|Win32
20 | {F121FD3F-B62E-4F0A-9BC5-84606D6CA2D5}.Release|x64.ActiveCfg = Release|x64
21 | {F121FD3F-B62E-4F0A-9BC5-84606D6CA2D5}.Release|x64.Build.0 = Release|x64
22 | {F121FD3F-B62E-4F0A-9BC5-84606D6CA2D5}.Release|x86.ActiveCfg = Release|Win32
23 | {F121FD3F-B62E-4F0A-9BC5-84606D6CA2D5}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 04/Static/Car Abstraction/Car Abstraction/Car.cpp:
--------------------------------------------------------------------------------
1 | #include "Car.h"
2 | #include
3 | int Car::totalCount = 0;
4 | Car::Car():Car(0) {
5 | std::cout << "Car()" << std::endl;
6 | }
7 |
8 | Car::Car(float amount):Car(amount, 0) {
9 | std::cout << "Car(float)" << std::endl;
10 |
11 | }
12 |
13 | Car::Car(float amount, int pass) {
14 | std::cout << "Car(float, int)" << std::endl;
15 | ++totalCount;
16 | fuel = amount;
17 | speed = 0;
18 | passengers = pass;
19 | }
20 |
21 | Car::~Car() {
22 | --totalCount;
23 | std::cout << "~Car()" << std::endl;
24 | }
25 |
26 | void Car::FillFuel(float amount) {
27 | fuel = amount;
28 | }
29 |
30 | void Car::Accelerate() {
31 | this->speed++;
32 | this->fuel -= 0.5f;
33 | }
34 |
35 | void Car::Brake() {
36 | speed = 0;
37 | }
38 |
39 | void Car::AddPassengers(int count) {
40 | passengers = count;
41 | }
42 |
43 | void Car::Dashboard()const {
44 | std::cout << "Fuel:" << fuel << std::endl;
45 | std::cout << "Speed:" << speed << std::endl;
46 | std::cout << "Passengers:" << passengers << std::endl;
47 | }
48 |
49 | void Car::ShowCount() {
50 | std::cout << "Total cars : " << totalCount << std::endl;
51 | }
52 |
--------------------------------------------------------------------------------
/Section 04/Static/Car Abstraction/Car Abstraction/Car.h:
--------------------------------------------------------------------------------
1 | //#pragma once
2 | class Car {
3 | private:
4 | float fuel;
5 | float speed;
6 | int passengers;
7 | static int totalCount;
8 | public:
9 | Car();
10 | Car(float amount);
11 | Car(float amount, int pass);
12 | ~Car();
13 | void FillFuel(float amount);
14 | void Accelerate();
15 | void Brake();
16 | void AddPassengers(int count);
17 | void Dashboard()const;
18 | static void ShowCount();
19 | };
--------------------------------------------------------------------------------
/Section 04/Static/Car Abstraction/Car Abstraction/main.cpp:
--------------------------------------------------------------------------------
1 | #include "Car.h"
2 | int main() {
3 | Car c;
4 |
5 | return 0;
6 | }
--------------------------------------------------------------------------------
/Section 04/Static/Car Abstraction/backup/Car.cpp:
--------------------------------------------------------------------------------
1 | #include "Car.h"
2 | #include
3 | int Car::totalCount = 0;
4 | Car::Car():Car(0) {
5 | std::cout << "Car()" << std::endl;
6 | }
7 |
8 | Car::Car(float amount):Car(amount, 0) {
9 | std::cout << "Car(float)" << std::endl;
10 |
11 | }
12 |
13 | Car::Car(float amount, int pass) {
14 | std::cout << "Car(float, int)" << std::endl;
15 | ++totalCount;
16 | fuel = amount;
17 | speed = 0;
18 | passengers = pass;
19 | }
20 |
21 | Car::~Car() {
22 | --totalCount;
23 | std::cout << "~Car()" << std::endl;
24 | }
25 |
26 | void Car::FillFuel(float amount) {
27 | fuel = amount;
28 | }
29 |
30 | void Car::Accelerate() {
31 | this->speed++;
32 | this->fuel -= 0.5f;
33 | }
34 |
35 | void Car::Brake() {
36 | speed = 0;
37 | }
38 |
39 | void Car::AddPassengers(int count) {
40 | passengers = count;
41 | }
42 |
43 | void Car::Dashboard() {
44 | std::cout << "Fuel:" << fuel << std::endl;
45 | std::cout << "Speed:" << speed << std::endl;
46 | std::cout << "Passengers:" << passengers << std::endl;
47 | }
48 |
49 | void Car::ShowCount() {
50 | std::cout << "Total cars : " << totalCount << std::endl;
51 | }
52 |
--------------------------------------------------------------------------------
/Section 04/Static/Car Abstraction/backup/Car.h:
--------------------------------------------------------------------------------
1 | //#pragma once
2 | class Car {
3 | private:
4 | float fuel;
5 | float speed;
6 | int passengers;
7 | static int totalCount;
8 | public:
9 | Car();
10 | Car(float amount);
11 | Car(float amount, int pass);
12 | ~Car();
13 | void FillFuel(float amount);
14 | void Accelerate();
15 | void Brake();
16 | void AddPassengers(int count);
17 | void Dashboard();
18 | static void ShowCount();
19 | };
--------------------------------------------------------------------------------
/Section 04/Static/Car Abstraction/backup/main.cpp:
--------------------------------------------------------------------------------
1 |
2 | int main() {
3 | int & a = int(3);
4 |
5 | return 0;
6 | }
--------------------------------------------------------------------------------
/Section 04/class/Car/Car.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Car", "Car\Car.vcxproj", "{C6F480F9-DCD4-4193-81A2-948D2D4173C9}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {C6F480F9-DCD4-4193-81A2-948D2D4173C9}.Debug|x64.ActiveCfg = Debug|x64
17 | {C6F480F9-DCD4-4193-81A2-948D2D4173C9}.Debug|x64.Build.0 = Debug|x64
18 | {C6F480F9-DCD4-4193-81A2-948D2D4173C9}.Debug|x86.ActiveCfg = Debug|Win32
19 | {C6F480F9-DCD4-4193-81A2-948D2D4173C9}.Debug|x86.Build.0 = Debug|Win32
20 | {C6F480F9-DCD4-4193-81A2-948D2D4173C9}.Release|x64.ActiveCfg = Release|x64
21 | {C6F480F9-DCD4-4193-81A2-948D2D4173C9}.Release|x64.Build.0 = Release|x64
22 | {C6F480F9-DCD4-4193-81A2-948D2D4173C9}.Release|x86.ActiveCfg = Release|Win32
23 | {C6F480F9-DCD4-4193-81A2-948D2D4173C9}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 04/class/Car/Car/Car.cpp:
--------------------------------------------------------------------------------
1 | #include "Car.h"
2 | #include
3 |
4 | Car::Car() {
5 |
6 | }
7 | Car::Car(float amount) {
8 | fuel = amount;
9 |
10 | }
11 | void Car::FillFuel(float amount) {
12 | fuel = amount;
13 | }
14 |
15 | void Car::Accelerate() {
16 | speed++;
17 | fuel -= 0.5f;
18 | }
19 |
20 | void Car::Brake() {
21 | speed = 0;
22 | }
23 |
24 | void Car::AddPassengers(int count) {
25 | passengers = count;
26 | }
27 |
28 | void Car::Dashboard() {
29 | std::cout << "Fuel level : " << fuel << std::endl;
30 | std::cout << "Speed : " << speed << std::endl;
31 | std::cout << "Passengers : " << passengers << std::endl;
32 | }
33 |
34 | Car::~Car() {
35 | }
36 |
--------------------------------------------------------------------------------
/Section 04/class/Car/Car/Car.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | struct Car {
3 | private:
4 | float fuel{ 0 };
5 | float speed{ 0 };
6 | int passengers{ 0 };
7 | int arr[5] = { 1,2,3 };
8 | char *p{};
9 | public:
10 | Car();
11 | Car(float amount);
12 | void FillFuel(float amount);
13 | void Accelerate();
14 | void Brake();
15 | void AddPassengers(int count);
16 | void Dashboard();
17 | ~Car();
18 | };
19 |
--------------------------------------------------------------------------------
/Section 04/class/Car/Car/Car.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 |
23 |
24 | Source Files
25 |
26 |
27 | Source Files
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Section 04/class/Car/Car/main.cpp:
--------------------------------------------------------------------------------
1 | #include "Car.h"
2 | #include
3 | int main() {
4 | Car c(5);
5 | c.Dashboard();
6 | return 0;
7 | }
--------------------------------------------------------------------------------
/Section 04/structure/Structure/Structure.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Structure", "Structure\Structure.vcxproj", "{8846CB52-CBDC-4EFD-8D47-007205BF023C}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {8846CB52-CBDC-4EFD-8D47-007205BF023C}.Debug|x64.ActiveCfg = Debug|x64
17 | {8846CB52-CBDC-4EFD-8D47-007205BF023C}.Debug|x64.Build.0 = Debug|x64
18 | {8846CB52-CBDC-4EFD-8D47-007205BF023C}.Debug|x86.ActiveCfg = Debug|Win32
19 | {8846CB52-CBDC-4EFD-8D47-007205BF023C}.Debug|x86.Build.0 = Debug|Win32
20 | {8846CB52-CBDC-4EFD-8D47-007205BF023C}.Release|x64.ActiveCfg = Release|x64
21 | {8846CB52-CBDC-4EFD-8D47-007205BF023C}.Release|x64.Build.0 = Release|x64
22 | {8846CB52-CBDC-4EFD-8D47-007205BF023C}.Release|x86.ActiveCfg = Release|Win32
23 | {8846CB52-CBDC-4EFD-8D47-007205BF023C}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 04/structure/Structure/Structure/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | struct Point {
3 | int x;
4 | int y;
5 | };
6 | void DrawLine(int x1, int y1, int x2, int y2) {
7 |
8 | }
9 | //More natural and easy to understand
10 | void DrawLine(Point start, Point end) {
11 | std::cout << start.x << std::endl;
12 | }
13 | int main() {
14 |
15 | return 0;
16 | }
--------------------------------------------------------------------------------
/Section 04/structure/Structure/Structure/Structure.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 05/Lvalues and rvalues/RValues/RValues.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RValues", "RValues\RValues.vcxproj", "{0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Debug|x64.ActiveCfg = Debug|x64
17 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Debug|x64.Build.0 = Debug|x64
18 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Debug|x86.ActiveCfg = Debug|Win32
19 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Debug|x86.Build.0 = Debug|Win32
20 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Release|x64.ActiveCfg = Release|x64
21 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Release|x64.Build.0 = Release|x64
22 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Release|x86.ActiveCfg = Release|Win32
23 | {0A34BDF7-F3B4-4C7A-8831-7B1FBBB1B904}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 05/Lvalues and rvalues/RValues/RValues/RValues.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 05/Lvalues and rvalues/RValues/RValues/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | //Returns r-value
4 | int Add(int x, int y) {
5 | return x + y;
6 | }
7 | //Return l-value
8 | int & Transform(int &x) {
9 | x *= x;
10 | return x;
11 | }
12 |
13 | void Print(int &x) {
14 | std::cout << "Print(int&)" << std::endl;
15 | }
16 | void Print(const int &x) {
17 | std::cout << "Print(const int&)" << std::endl;
18 |
19 | }
20 | void Print(int &&x) {
21 | std::cout << "Print(int &&)" << std::endl;
22 | }
23 | int main() {
24 | //x is lvalue
25 | int x = 10;
26 |
27 | //ref is l-value reference
28 | int &ref = x ;
29 | //Transform returns an l-value
30 | int &ref2 = Transform(x) ;
31 | //Binds to function that accepts l-value reference
32 | Print(x);
33 |
34 |
35 | //rv is r-value reference
36 | int &&rv = 8 ;
37 |
38 | //Add returns a temporary (r-value)
39 | int &&rv2 = Add(3,5) ;
40 | //Binds to function that accepts a temporary, i.e. r-value reference
41 | Print(3);
42 | return 0;
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/Section 05/Move Semantics Impl/Copy Ctor - Complete/Copy Ctor.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Copy Ctor", "Copy Ctor\Copy Ctor.vcxproj", "{94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x64.ActiveCfg = Debug|x64
17 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x64.Build.0 = Debug|x64
18 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x86.ActiveCfg = Debug|Win32
19 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x86.Build.0 = Debug|Win32
20 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x64.ActiveCfg = Release|x64
21 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x64.Build.0 = Release|x64
22 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x86.ActiveCfg = Release|Win32
23 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 05/Move Semantics Impl/Copy Ctor - Complete/Copy Ctor/Copy Ctor.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 |
23 |
24 | Source Files
25 |
26 |
27 | Source Files
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Section 05/Move Semantics Impl/Copy Ctor - Complete/Copy Ctor/Integer.cpp:
--------------------------------------------------------------------------------
1 | #include "Integer.h"
2 | #include
3 | Integer::Integer() {
4 | std::cout << "Integer()" << std::endl;
5 | m_pInt = new int(0);
6 | }
7 |
8 | Integer::Integer(int value) {
9 | std::cout << "Integer(int)" << std::endl;
10 | m_pInt = new int(value);
11 | }
12 |
13 | Integer::Integer(const Integer & obj) {
14 | std::cout << "Integer(const Integer&)" << std::endl;
15 | m_pInt = new int(*obj.m_pInt);
16 | }
17 |
18 | Integer::Integer(Integer && obj) {
19 | std::cout << "Integer(int&&)" << std::endl;
20 | m_pInt = obj.m_pInt;
21 | obj.m_pInt = nullptr;
22 | }
23 |
24 | int Integer::GetValue() const {
25 | return *m_pInt;
26 | }
27 |
28 | void Integer::SetValue(int value) {
29 | *m_pInt = value;
30 | }
31 |
32 | Integer::~Integer() {
33 | std::cout << "~Integer()" << std::endl;
34 | delete m_pInt;
35 | }
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/Section 05/Move Semantics Impl/Copy Ctor - Complete/Copy Ctor/Integer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | class Integer {
4 | int *m_pInt;
5 | public:
6 | //Default constructor
7 | Integer();
8 | //Parameterized constructor
9 | Integer(int value);
10 | //Copy constructor
11 | Integer(const Integer &obj);
12 | //Move constructor
13 | Integer(Integer &&obj);
14 | int GetValue()const;
15 | void SetValue(int value);
16 | ~Integer();
17 |
18 | };
19 |
--------------------------------------------------------------------------------
/Section 05/Move Semantics Impl/Copy Ctor - Complete/Copy Ctor/main.cpp:
--------------------------------------------------------------------------------
1 | #include "Integer.h"
2 | #include
3 |
4 | Integer Add(const Integer &a, const Integer &b){
5 | Integer temp ;
6 | temp.SetValue(a.GetValue() + b.GetValue()) ;
7 | return temp ;
8 | }
9 | int main() {
10 | Integer a(1), b(3) ;
11 | a.SetValue(Add(a,b).GetValue()) ;
12 |
13 |
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/Section 05/RuleofFive/RuleofFive/Integer.cpp:
--------------------------------------------------------------------------------
1 | #include "Integer.h"
2 | #include
3 | Integer::Integer() {
4 | std::cout << "Integer()" << std::endl;
5 | m_pInt = new int(0);
6 | }
7 |
8 | Integer::Integer(int value) {
9 | std::cout << "Integer(int)" << std::endl;
10 | m_pInt = new int(value);
11 | }
12 |
13 | Integer::Integer(const Integer & obj) {
14 | std::cout << "Integer(const Integer&)" << std::endl;
15 | m_pInt = new int(*obj.m_pInt);
16 | }
17 |
18 | Integer::Integer(Integer && obj) {
19 | std::cout << "Integer(Integer&&)" << std::endl;
20 | m_pInt = obj.m_pInt;
21 | obj.m_pInt = nullptr;
22 | }
23 |
24 | Integer& Integer::operator=(const Integer& obj)
25 | {
26 | std::cout << "operator=(const Integer& obj)" << std::endl;
27 | if(this == &obj){
28 | return *this ;
29 | }
30 | delete m_pInt ;
31 | m_pInt = new int(*obj.m_pInt);
32 | return *this ;
33 | }
34 |
35 | Integer& Integer::operator=(Integer&& obj)
36 | {
37 | std::cout << "operator=(Integer&& obj)" << std::endl;
38 | if(this == &obj){
39 | return *this ;
40 | }
41 | delete m_pInt ;
42 | m_pInt = obj.m_pInt;
43 | obj.m_pInt = nullptr;
44 | return *this ;
45 | }
46 |
47 | int Integer::GetValue() const {
48 | return *m_pInt;
49 | }
50 |
51 | void Integer::SetValue(int value) {
52 | *m_pInt = value;
53 | }
54 |
55 | Integer::~Integer() {
56 | std::cout << "~Integer()" << std::endl;
57 | delete m_pInt;
58 | }
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/Section 05/RuleofFive/RuleofFive/Integer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | class Integer {
4 | int *m_pInt;
5 | public:
6 | //Default constructor
7 | Integer();
8 |
9 | //Parameterized constructor
10 | Integer(int value);
11 |
12 | //Copy constructor
13 | Integer(const Integer &obj);
14 |
15 | //Move constructor
16 | Integer(Integer &&obj);
17 |
18 | //Copy assignment
19 | Integer & operator=(const Integer &obj) ;
20 |
21 | //Move assignment
22 | Integer & operator=(Integer && obj) ;
23 |
24 | int GetValue()const;
25 | void SetValue(int value);
26 | ~Integer();
27 |
28 | };
29 |
--------------------------------------------------------------------------------
/Section 05/RuleofFive/RuleofFive/RuleofFive.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 |
26 |
27 | Header Files
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Section 05/RuleofFive/RuleofFive/main.cpp:
--------------------------------------------------------------------------------
1 | #include "Integer.h"
2 | class Number{
3 | Integer m_Value{} ;
4 | public:
5 | Number()=default ;
6 | Number(int value):m_Value{value}{
7 | }
8 | /*Number(const Number &n):m_Value{n.m_Value}{
9 | }*/
10 | /*~Number(){
11 | }*/
12 | Number(Number &&n) = default ;
13 | Number(const Number &n) = default ;
14 | Number & operator=(Number&&)=default ;
15 | Number & operator=(const Number&)=default ;
16 | };
17 | Number CreateNumber(int num){
18 | Number n{num} ;
19 | return n ;
20 | }
21 | int main(){
22 | Number n1 ;
23 | auto n2{n1} ;
24 | n2 = n1 ;
25 |
26 | auto n3{CreateNumber(3)} ;
27 | n3 = CreateNumber(3) ;
28 | }
29 |
--------------------------------------------------------------------------------
/Section 06/Operator Overloading/Copy Ctor.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Copy Ctor", "Copy Ctor\Copy Ctor.vcxproj", "{94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x64.ActiveCfg = Debug|x64
17 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x64.Build.0 = Debug|x64
18 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x86.ActiveCfg = Debug|Win32
19 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Debug|x86.Build.0 = Debug|Win32
20 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x64.ActiveCfg = Release|x64
21 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x64.Build.0 = Release|x64
22 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x86.ActiveCfg = Release|Win32
23 | {94C4B85E-A02C-4C15-BFDF-AE03DB6DBE3E}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 06/Operator Overloading/Copy Ctor/Copy Ctor.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 |
23 |
24 | Source Files
25 |
26 |
27 | Source Files
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Section 06/Operator Overloading/Copy Ctor/Integer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | class Integer {
4 | int *m_pInt;
5 | public:
6 | //Default constructor
7 | Integer();
8 | //Parameterized constructor
9 | Integer(int value);
10 | //Copy constructor
11 | Integer(const Integer &obj);
12 | //Move constructor
13 | Integer(Integer &&obj);
14 | int GetValue()const;
15 | void SetValue(int value);
16 | ~Integer();
17 | Integer & operator ++();
18 | Integer operator ++(int);
19 | bool operator ==(const Integer &a)const;
20 |
21 | //Copy assignment
22 | Integer & operator =(const Integer &a);
23 | //Move assignment
24 | Integer & operator =(Integer &&a);
25 | Integer operator +(const Integer & a)const;
26 |
27 | void operator ()();
28 | };
29 | Integer operator +(int x, const Integer &y);
30 | std::ostream & operator <<(std::ostream & out, const Integer &a);
31 | std::istream & operator >> (std::istream &input, Integer &a);
--------------------------------------------------------------------------------
/Section 06/Operator Overloading/Copy Ctor/main.cpp:
--------------------------------------------------------------------------------
1 | #include "Integer.h"
2 | #include
3 | #include
4 | class IntPtr {
5 | Integer *m_p;
6 | public:
7 | IntPtr(Integer *p) :m_p(p) {
8 |
9 | }
10 | ~IntPtr() {
11 | delete m_p;
12 | }
13 | Integer *operator ->() {
14 | return m_p;
15 | }
16 | Integer & operator *() {
17 | return *m_p;
18 | }
19 | };
20 | void CreateInteger() {
21 | std::unique_ptr p(new Integer);
22 | //auto p2(p);
23 | (*p).SetValue(3);
24 | //std::cout << p->GetValue() << std::endl;
25 | }
26 | void Process(Integer val) {
27 |
28 | }
29 |
30 | int main() {
31 | Integer a(3);
32 | /*auto b(std::move(a));
33 | std::cout << a << std::endl;*/
34 | Process(std::move(a));
35 | return 0;
36 | }
--------------------------------------------------------------------------------
/Section 06/UserDefConversions/UserDefConversions/Integer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | class Integer {
4 | int *m_pInt;
5 | public:
6 | //Default constructor
7 | Integer();
8 | //Parameterized constructor
9 | Integer(int value);
10 | //Copy constructor
11 | Integer(const Integer &obj);
12 | //Move constructor
13 | Integer(Integer &&obj);
14 | int GetValue()const;
15 | void SetValue(int value);
16 | ~Integer();
17 | Integer & operator ++();
18 | Integer operator ++(int);
19 | bool operator ==(const Integer &a)const;
20 |
21 | //Copy assignment
22 | Integer & operator =(const Integer &a);
23 | //Move assignment
24 | Integer & operator =(Integer &&a);
25 | Integer operator +(const Integer & a)const;
26 |
27 | void operator ()();
28 | };
29 | Integer operator +(int x, const Integer &y);
30 | std::ostream & operator <<(std::ostream & out, const Integer &a);
31 | std::istream & operator >> (std::istream &input, Integer &a);
--------------------------------------------------------------------------------
/Section 06/UserDefConversions/UserDefConversions/UserDefConversions.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 |
26 |
27 | Header Files
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Section 06/UserDefConversions/UserDefConversions/UserDefConversions.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Section 06/UserDefConversions/UserDefConversions/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "Integer.h"
3 | class Product{
4 | Integer m_Id ;
5 | public:
6 | Product(const Integer &id):m_Id{id} {
7 | std::cout << "Product(const Integer &)" << std::endl;
8 | }
9 | ~Product(){
10 | std::cout << "~" ;
11 | }
12 | const Integer & GetInteger()const{
13 | return m_Id ;
14 | }
15 | operator Integer(){
16 | return m_Id ;
17 | }
18 | };
19 |
20 | int main() {
21 | Product p{5} ;
22 | Integer id{5} ;
23 | //id = p ; // id = p.operator Integer() ;
24 |
25 | if(id == p){
26 | std::cout << "Id matches with the product\n" ;
27 | }
28 |
29 | return 0;
30 | }
--------------------------------------------------------------------------------
/Section 07/CircularRef/CircularRef/CircularRef.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 07/CircularRef/CircularRef/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | class Employee ;
3 | class Project {
4 | public:
5 | std::shared_ptr m_emp ;
6 | Project() {
7 | std::cout << "Project()" << std::endl;
8 | }
9 | ~Project() {
10 | std::cout << "~Project()" << std::endl;
11 | }
12 | };
13 | class Employee {
14 | public:
15 | //std::shared_ptr m_prj ;
16 | std::weak_ptr m_prj ;
17 | Employee() {
18 | std::cout << "Employee()" << std::endl;
19 | }
20 |
21 | ~Employee() {
22 | std::cout << "~Employee()" << std::endl;
23 | }
24 | };
25 |
26 | int main() {
27 | std::shared_ptr emp{new Employee{}} ;
28 | std::shared_ptr prj{new Project{}} ;
29 | emp->m_prj = prj ;
30 | prj->m_emp = emp ;
31 | }
--------------------------------------------------------------------------------
/Section 07/More Features/More Features/More Features.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 07/shared_ptr/shared_ptr/Integer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | class Integer {
4 | int *m_pInt;
5 | public:
6 | //Default constructor
7 | Integer();
8 | //Parameterized constructor
9 | Integer(int value);
10 | //Copy constructor
11 | Integer(const Integer &obj);
12 | //Move constructor
13 | Integer(Integer &&obj);
14 | int GetValue()const;
15 | void SetValue(int value);
16 | ~Integer();
17 | Integer & operator ++();
18 | Integer operator ++(int);
19 | bool operator ==(const Integer &a)const;
20 |
21 | //Copy assignment
22 | Integer & operator =(const Integer &a);
23 | //Move assignment
24 | Integer & operator =(Integer &&a);
25 | Integer operator +(const Integer & a)const;
26 |
27 | void operator ()();
28 | };
29 | Integer operator +(int x, const Integer &y);
30 | std::ostream & operator <<(std::ostream & out, const Integer &a);
31 | std::istream & operator >> (std::istream &input, Integer &a);
--------------------------------------------------------------------------------
/Section 07/shared_ptr/shared_ptr/Source.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | class Project {
6 | std::string m_Name ;
7 | public:
8 | void SetName(const std::string &name) {
9 | m_Name = name ;
10 | }
11 | void ShowProjectDetails()const {
12 | std::cout << "[Project Name]" << m_Name << '\n' ;
13 | }
14 | };
15 |
16 | class Employee {
17 | std::shared_ptr m_pProject{} ;
18 | public:
19 | void SetProject(const std::shared_ptr &prj) {
20 | m_pProject = prj ;
21 | }
22 | const std::shared_ptr& GetProject()const {
23 | return m_pProject ;
24 | }
25 | };
26 | void ShowInfo(const std::shared_ptr & emp) {
27 | std::cout << "Employee project details:" ;
28 | emp->GetProject()->ShowProjectDetails() ;
29 | }
30 | int main() {
31 | std::shared_ptr prj { new Project{}} ;
32 | prj->SetName("Video Decoder") ;
33 | std::shared_ptr e1 {new Employee{}} ;
34 | e1->SetProject(prj) ;
35 | std::shared_ptr e2 { new Employee{} };
36 | e2->SetProject(prj) ;
37 | std::shared_ptr e3 { new Employee{}} ;
38 | e3->SetProject(prj) ;
39 |
40 | e3.reset(new Employee{}) ;
41 | if(e3) {
42 | //Valid
43 | }else {
44 | //Not valid
45 | }
46 |
47 | std::cout << "Reference count:" << prj.use_count() << '\n' ;
48 | //ShowInfo(e1) ;
49 | //ShowInfo(e2) ;
50 | prj->ShowProjectDetails() ;
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/Section 07/shared_ptr/shared_ptr/shared_ptr.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 |
26 |
27 | Header Files
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Section 07/unique_ptr/unique_ptr/Integer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | class Integer {
4 | int *m_pInt;
5 | public:
6 | //Default constructor
7 | Integer();
8 | //Parameterized constructor
9 | Integer(int value);
10 | //Copy constructor
11 | Integer(const Integer &obj);
12 | //Move constructor
13 | Integer(Integer &&obj);
14 | int GetValue()const;
15 | void SetValue(int value);
16 | ~Integer();
17 | Integer & operator ++();
18 | Integer operator ++(int);
19 | bool operator ==(const Integer &a)const;
20 |
21 | //Copy assignment
22 | Integer & operator =(const Integer &a);
23 | //Move assignment
24 | Integer & operator =(Integer &&a);
25 | Integer operator +(const Integer & a)const;
26 |
27 | void operator ()();
28 | };
29 | Integer operator +(int x, const Integer &y);
30 | std::ostream & operator <<(std::ostream & out, const Integer &a);
31 | std::istream & operator >> (std::istream &input, Integer &a);
--------------------------------------------------------------------------------
/Section 07/unique_ptr/unique_ptr/Source.cpp:
--------------------------------------------------------------------------------
1 | #include "integer.h"
2 | #include
3 | void Display(Integer *p) {
4 | if(!p) {
5 | return ;
6 | }
7 | std::cout << p->GetValue() << std::endl;
8 | }
9 | Integer *GetPointer(int value) {
10 | Integer *p = new Integer{value} ;
11 | return p ;
12 | }
13 | void Store(std::unique_ptr &p) {
14 | std::cout << "Storing data into a file:" << p->GetValue() << std::endl;
15 | }
16 | void Operate(int value) {
17 | std::unique_ptr p{GetPointer(value)} ;
18 | if(p == nullptr) {
19 | //p = new Integer{value} ;
20 | p.reset(new Integer{value}) ;
21 | }
22 | p->SetValue(100) ;
23 | Display(p.get()) ;
24 | //delete p ;
25 | //p = nullptr ;
26 | //p = new Integer{} ;
27 | p.reset(new Integer{}) ;
28 | *p = __LINE__ ;
29 | Display(p.get()) ;
30 | Store(p) ;
31 | //delete p ;
32 | }
33 | int main() {
34 | Operate(5) ;
35 | }
--------------------------------------------------------------------------------
/Section 07/unique_ptr/unique_ptr/unique_ptr.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 |
26 |
27 | Header Files
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Section 07/weak_ptr/weak_ptr/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | class Printer {
3 | std::weak_ptr m_pValue{} ;
4 | public:
5 | void SetValue(std::weak_ptr p) {
6 | m_pValue = p ;
7 | }
8 | void Print() {
9 | if(m_pValue.expired()) {
10 | std::cout << "Resource is no longer available" << std::endl;
11 | return ;
12 | }
13 | auto sp = m_pValue.lock() ;
14 | std::cout << "Value is:" << *sp << std::endl ;
15 | std::cout << "Ref count:" << sp.use_count() << std::endl ;
16 | }
17 | };
18 | int main() {
19 | Printer prn ;
20 | int num{} ;
21 | std::cin >> num ;
22 | std::shared_ptr p{new int{num}} ;
23 | prn.SetValue(p) ;
24 | if(*p > 10) {
25 | p = nullptr ;
26 | }
27 | prn.Print() ;
28 | }
--------------------------------------------------------------------------------
/Section 07/weak_ptr/weak_ptr/weak_ptr.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 08/StringStreams/StringStreams/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | int main() {
4 | /*
5 | int a{5}, b{6} ;
6 | int sum = a + b ;
7 | std::stringstream ss ;
8 | ss << "Sum of " << a << " & " << b << " is :" << sum << std::endl;
9 | std::string s = ss.str() ;
10 | std::cout << s << std::endl;
11 | ss.str("") ;
12 | ss << sum ;
13 | auto ssum = std::to_string(sum) ;
14 | std::cout << ssum << std::endl;
15 | */
16 | std::string data = "12 89 21" ;
17 | int a ;
18 | std::stringstream ss ;
19 | ss.str(data) ;
20 | while(ss >> a) {
21 | std::cout << a << std::endl;
22 | }
23 | int x = std::stoi("54") ;
24 | return 0 ;
25 |
26 | }
--------------------------------------------------------------------------------
/Section 08/StringStreams/StringStreams/StringStreams.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 08/Strings/Strings/Strings.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 08/UserDefinedLiterals/UserDefinedLiterals/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | class Distance {
3 | long double m_Kilometres;
4 | public:
5 | Distance(long double km) :m_Kilometres{ km } {
6 |
7 | }
8 | long double GetKm()const {
9 | return m_Kilometres;
10 | }
11 | void SetKm(long double val) {
12 | m_Kilometres = val;
13 | }
14 | };
15 | Distance operator"" _mi(long double val) {
16 | return Distance{ val * 1.6 };
17 | }
18 | Distance operator"" _metres(long double val) {
19 | return Distance{ val / 1000 };
20 | }
21 | int main() {
22 | Distance dist{ 32.0_mi };
23 | Distance d2{ 7123.0_metres };
24 | std::cout << d2.GetKm() << std::endl;
25 | return 0;
26 | }
--------------------------------------------------------------------------------
/Section 08/UserDefinedLiterals/UserDefinedLiterals/UserDefinedLiterals.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 08/Vector/Vector.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Vector", "Vector\Vector.vcxproj", "{C0DC5792-090C-42FA-8A71-121EB2172497}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {C0DC5792-090C-42FA-8A71-121EB2172497}.Debug|x64.ActiveCfg = Debug|x64
17 | {C0DC5792-090C-42FA-8A71-121EB2172497}.Debug|x64.Build.0 = Debug|x64
18 | {C0DC5792-090C-42FA-8A71-121EB2172497}.Debug|x86.ActiveCfg = Debug|Win32
19 | {C0DC5792-090C-42FA-8A71-121EB2172497}.Debug|x86.Build.0 = Debug|Win32
20 | {C0DC5792-090C-42FA-8A71-121EB2172497}.Release|x64.ActiveCfg = Release|x64
21 | {C0DC5792-090C-42FA-8A71-121EB2172497}.Release|x64.Build.0 = Release|x64
22 | {C0DC5792-090C-42FA-8A71-121EB2172497}.Release|x86.ActiveCfg = Release|Win32
23 | {C0DC5792-090C-42FA-8A71-121EB2172497}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 08/Vector/Vector/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | int main() {
4 | int arr[10];
5 | int *ptr = new int[10];
6 | for (int i = 0; i < 10; ++i) {
7 | ptr[i] = i * 10;
8 | }
9 |
10 | std::vector data{ 1,2,3 };
11 | for (int i = 0; i < 5; ++i) {
12 | data.push_back(i * 10);
13 | }
14 | //Access
15 | data[0] = 100;
16 | // std::cout << data[i] << " ";
17 | //}
18 | for (auto x : data) {
19 | std::cout << x << " ";
20 | }
21 | auto it = data.begin();
22 | //std::cout << *it;
23 | ++it;
24 |
25 | --it;
26 | it = it + 5;
27 | //Delete
28 | it = data.begin();
29 | data.erase(it);
30 | std::cout << std::endl;
31 | for (auto x : data) {
32 | std::cout << x << " ";
33 | }
34 | //Insert
35 | it = data.begin() + 5;
36 | data.insert(it, 500);
37 | std::cout << std::endl;
38 | for (auto x : data) {
39 | std::cout << x << " ";
40 | }
41 | return 0;
42 | }
--------------------------------------------------------------------------------
/Section 08/Vector/Vector/Vector.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 08/constexpr/constexpr/constexpr.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "constexpr", "constexpr\constexpr.vcxproj", "{A9069081-EAC1-4C09-A498-E741AD02182C}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {A9069081-EAC1-4C09-A498-E741AD02182C}.Debug|x64.ActiveCfg = Debug|x64
17 | {A9069081-EAC1-4C09-A498-E741AD02182C}.Debug|x64.Build.0 = Debug|x64
18 | {A9069081-EAC1-4C09-A498-E741AD02182C}.Debug|x86.ActiveCfg = Debug|Win32
19 | {A9069081-EAC1-4C09-A498-E741AD02182C}.Debug|x86.Build.0 = Debug|Win32
20 | {A9069081-EAC1-4C09-A498-E741AD02182C}.Release|x64.ActiveCfg = Release|x64
21 | {A9069081-EAC1-4C09-A498-E741AD02182C}.Release|x64.Build.0 = Release|x64
22 | {A9069081-EAC1-4C09-A498-E741AD02182C}.Release|x86.ActiveCfg = Release|Win32
23 | {A9069081-EAC1-4C09-A498-E741AD02182C}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 08/constexpr/constexpr/constexpr/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | constexpr int GetNumber() {
4 | return 42;
5 | }
6 | constexpr int Add(int x, int y) {
7 | return x + y;
8 | }
9 | constexpr int Max(int x, int y) {
10 | //Needs C++14 compiler
11 | //if (x > y)
12 | // return x;
13 | //return y;
14 | return x > y ? x : y;
15 | }
16 | int main() {
17 | //Behaves as a constexpr function
18 | constexpr int i = GetNumber();
19 | int arr[i];
20 |
21 | //Behaves as a constexpr function
22 | const int j = GetNumber();
23 | int arr1[j];
24 |
25 | //Behaves as a normal function
26 | int x = GetNumber();
27 |
28 | //Error x is not constexpr
29 | //constexpr int sum = Add(x, 5);
30 |
31 | //Behaves as a normal function.
32 | int sum2 = Add(3, 5);
33 |
34 | return 0;
35 | }
36 | /*Constant expression function rules
37 |
38 | 1. Should accept and return literal types only
39 | (void, scalar types(int, float, char), references, etc....)
40 | 2. Should contain only single line statement that should be a return statement
41 |
42 | 3. constexpr functions are implicitly inline
43 | */
--------------------------------------------------------------------------------
/Section 08/constexpr/constexpr/constexpr/constexpr.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 08/enums/enums/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | enum class Color : long{RED=5, GREEN, BLUE} ;
3 | void FillColor(Color color) {
4 | //Fill background with some color
5 | if(color == Color::RED) {
6 | //Paint with red color
7 | std::cout << "RED" << std::endl;
8 | }
9 | else if(color == Color::GREEN) {
10 | //Paint with green color
11 | std::cout << "GREEN" << std::endl;
12 | }
13 | else if(color == Color::BLUE) {
14 | //Paint with blue color
15 | std::cout << "BLUE" << std::endl;
16 | }
17 | }
18 | enum class TrafficLight : char{RED='c', GREEN, YELLOW} ;
19 | int main() {
20 | Color c = Color::RED ;
21 | FillColor(c) ;
22 | FillColor(Color::GREEN) ;
23 | FillColor(static_cast(2)) ;
24 | int x = static_cast(Color::RED) ;
25 | return 0;
26 | }
--------------------------------------------------------------------------------
/Section 08/enums/enums/enums.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 08/initializer_list/InitializerList/InitializerList.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InitializerList", "InitializerList\InitializerList.vcxproj", "{99A9BD6B-9F9C-437C-A8F8-7C025722015E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {99A9BD6B-9F9C-437C-A8F8-7C025722015E}.Debug|x64.ActiveCfg = Debug|x64
17 | {99A9BD6B-9F9C-437C-A8F8-7C025722015E}.Debug|x64.Build.0 = Debug|x64
18 | {99A9BD6B-9F9C-437C-A8F8-7C025722015E}.Debug|x86.ActiveCfg = Debug|Win32
19 | {99A9BD6B-9F9C-437C-A8F8-7C025722015E}.Debug|x86.Build.0 = Debug|Win32
20 | {99A9BD6B-9F9C-437C-A8F8-7C025722015E}.Release|x64.ActiveCfg = Release|x64
21 | {99A9BD6B-9F9C-437C-A8F8-7C025722015E}.Release|x64.Build.0 = Release|x64
22 | {99A9BD6B-9F9C-437C-A8F8-7C025722015E}.Release|x86.ActiveCfg = Release|Win32
23 | {99A9BD6B-9F9C-437C-A8F8-7C025722015E}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 08/initializer_list/InitializerList/InitializerList/InitializerList.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 09/Account/Account.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Account", "Account\Account.vcxproj", "{80C4613C-7892-4103-97A1-0A18BA8466DE}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {80C4613C-7892-4103-97A1-0A18BA8466DE}.Debug|x64.ActiveCfg = Debug|x64
17 | {80C4613C-7892-4103-97A1-0A18BA8466DE}.Debug|x64.Build.0 = Debug|x64
18 | {80C4613C-7892-4103-97A1-0A18BA8466DE}.Debug|x86.ActiveCfg = Debug|Win32
19 | {80C4613C-7892-4103-97A1-0A18BA8466DE}.Debug|x86.Build.0 = Debug|Win32
20 | {80C4613C-7892-4103-97A1-0A18BA8466DE}.Release|x64.ActiveCfg = Release|x64
21 | {80C4613C-7892-4103-97A1-0A18BA8466DE}.Release|x64.Build.0 = Release|x64
22 | {80C4613C-7892-4103-97A1-0A18BA8466DE}.Release|x86.ActiveCfg = Release|Win32
23 | {80C4613C-7892-4103-97A1-0A18BA8466DE}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 09/Account/Account/Account.cpp:
--------------------------------------------------------------------------------
1 | #include "Account.h"
2 | #include
3 | int Account::s_ANGenerator = 1000;
4 | Account::Account(const std::string &name, float balance):
5 | m_Name(name), m_Balance(balance){
6 | m_AccNo = ++s_ANGenerator;
7 | //std::cout << "Account(const std::string &, float)" << std::endl;
8 | }
9 |
10 |
11 | Account::~Account() {
12 | //std::cout << "~Account()" << std::endl;
13 |
14 | }
15 |
16 | const std::string Account::GetName() const {
17 | return m_Name;
18 | }
19 |
20 | float Account::GetBalance() const {
21 | return m_Balance;
22 | }
23 |
24 | int Account::GetAccountNo() const {
25 | return m_AccNo;
26 | }
27 |
28 | void Account::AccumulateInterest() {
29 | }
30 |
31 | void Account::Withdraw(float amount) {
32 | /*
33 | Balance should be greater than 0 & the amount
34 | to withdraw should be less than balance
35 | */
36 | if (amount < m_Balance && m_Balance > 0)
37 | m_Balance -= amount;
38 | else {
39 | //Throw an exception instead of printing a message
40 | //std::cout << "Insufficient balance" << std::endl;
41 | throw std::runtime_error("Insufficient balance");
42 | }
43 | }
44 |
45 | void Account::Deposit(float amount) {
46 | m_Balance += amount;
47 | }
48 |
49 | float Account::GetInterestRate() const {
50 | return 0.0f;
51 | }
52 |
--------------------------------------------------------------------------------
/Section 09/Account/Account/Account.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | class Account {
4 | std::string m_Name;
5 | int m_AccNo;
6 | static int s_ANGenerator;
7 | protected:
8 | float m_Balance;
9 | public:
10 | Account(const std::string &name, float balance);
11 | virtual ~Account();
12 | const std::string GetName()const;
13 | float GetBalance()const;
14 | int GetAccountNo()const;
15 |
16 | virtual void AccumulateInterest();
17 | virtual void Withdraw(float amount);
18 | void Deposit(float amount);
19 | virtual float GetInterestRate()const;
20 | };
21 |
22 |
--------------------------------------------------------------------------------
/Section 09/Account/Account/Checking.cpp:
--------------------------------------------------------------------------------
1 | #include "Checking.h"
2 |
3 | #include
4 | Checking::Checking(const std::string &name, float balance, float minbalance):
5 | m_MinimumBalance(minbalance), Account(name, balance){
6 | }
7 |
8 |
9 | Checking::~Checking() {
10 | }
11 |
12 | void Checking::Withdraw(float amount) {
13 | if ((m_Balance - amount) > m_MinimumBalance) {
14 | Account::Withdraw(amount);
15 | }
16 | else {
17 | std::cout << "Invalid amount" << std::endl;
18 | }
19 | }
20 |
21 | float Checking::GetMinimumBalance() const {
22 | return m_MinimumBalance;
23 | }
24 |
--------------------------------------------------------------------------------
/Section 09/Account/Account/Checking.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Account.h"
3 | class Checking :
4 | public Account {
5 | float m_MinimumBalance;
6 | public:
7 | using Account::Account;
8 | Checking(const std::string &name, float balance, float minbalance);
9 | ~Checking();
10 | void Withdraw(float amount)override;
11 | float GetMinimumBalance()const;
12 | };
13 |
14 |
--------------------------------------------------------------------------------
/Section 09/Account/Account/Savings.cpp:
--------------------------------------------------------------------------------
1 | #include "Savings.h"
2 | #include
3 |
4 | Savings::Savings(const std::string & name, float balance, float rate):Account(name, balance), m_Rate(rate) {
5 | //std::cout << "Savings(const std::string &, float)" << std::endl;
6 | }
7 |
8 | Savings::~Savings() {
9 | //std::cout << "~Savings()" << std::endl;
10 | }
11 |
12 | float Savings::GetInterestRate() const {
13 | return m_Rate;
14 | }
15 |
16 | void Savings::AccumulateInterest() {
17 | m_Balance += (m_Balance * m_Rate);
18 | }
19 |
--------------------------------------------------------------------------------
/Section 09/Account/Account/Savings.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Account.h"
3 | class Savings :
4 | public Account {
5 | float m_Rate;
6 | public:
7 | Savings(const std::string &name, float balance, float rate);
8 | ~Savings();
9 | float GetInterestRate()const override;
10 | void AccumulateInterest() override;
11 | };
12 |
13 |
--------------------------------------------------------------------------------
/Section 09/Account/Account/Transaction.cpp:
--------------------------------------------------------------------------------
1 | #include "Transaction.h"
2 | #include
3 | #include "Checking.h"
4 | void Transact(Account * pAccount) {
5 | std::cout << "Transaction started" << std::endl;
6 | std::cout << "Initial balance:" << pAccount->GetBalance() << std::endl;
7 | pAccount->Deposit(100);
8 | pAccount->AccumulateInterest();
9 | //if (typeid(*pAccount) == typeid(Checking)) {
10 | // Checking *pChecking = static_cast(pAccount);
11 | // std::cout << "Minimum balance of Checking:" << pChecking->GetMinimumBalance() << std::endl;
12 | //}
13 |
14 | Checking *pChecking = dynamic_cast(pAccount);
15 | if (pChecking != nullptr) {
16 | std::cout << "Minimum balance of Checking:" << pChecking->GetMinimumBalance() << std::endl;
17 | }
18 |
19 | pAccount->Withdraw(170);
20 | std::cout << "Interest rate:" << pAccount->GetInterestRate() << std::endl;
21 | std::cout << "Final balance:" << pAccount->GetBalance() << std::endl;
22 | }
23 |
--------------------------------------------------------------------------------
/Section 09/Account/Account/Transaction.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Account.h"
3 | void Transact(Account *pAccount);
4 |
--------------------------------------------------------------------------------
/Section 09/Account/Account/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "Savings.h"
3 | #include "Checking.h"
4 | #include "Transaction.h"
5 | #include
6 | int main()
7 | {
8 | Checking ch("Bob", 100, 50);
9 | Transact(&ch);
10 |
11 | return 0;
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/Section 10/ExceptionHandling-noexcept/ExceptionHandling-noexcept/ExceptionHandling-noexcept.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 10/ExceptionHandling-noexcept/ExceptionHandling-noexcept/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | void Test(int x)noexcept(false) {
3 | std::cout << x << std::endl;
4 | //throw x;
5 | }
6 | int Sum(int x, int y)noexcept(noexcept(Test(x))) {
7 | Test(x);
8 | return x + y;
9 | }
10 | class A {
11 | public:
12 | //Destructors are implicitly noexcept(true) in C++11
13 | ~A() {
14 | throw 3;
15 | }
16 | };
17 | int main() {
18 | A a;
19 | //boolalpha manipulator prints 0 & 1 as false & true
20 | std::cout << std::boolalpha << noexcept(a.~A()) << std::endl;
21 | try {
22 | Sum(3, 5);
23 | //Other statements
24 | }
25 | catch (int x) {
26 | std::cout << x << std::endl ;
27 | }
28 | }
--------------------------------------------------------------------------------
/Section 10/Exceptions in ctors/ExceptionHandlingII/ExceptionHandlingII/ExceptionHandlingII.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 10/Exceptions in ctors/ExceptionHandlingII/ExceptionHandlingII/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | class A {
5 | public:
6 | A() {
7 | std::cout << "A()" << std::endl;
8 | }
9 | ~A() {
10 | std::cout << "~A()" << std::endl;
11 | }
12 | };
13 | class B {
14 | public:
15 | B() {
16 | std::cout << "B()" << std::endl;
17 | }
18 | ~B() {
19 | std::cout << "~B()" << std::endl;
20 | }
21 | };
22 | class Test {
23 | std::unique_ptr pA{};
24 | B b{};
25 | std::unique_ptr pInt{};
26 | std::string pStr{};
27 | std::vector pArr{};
28 | public:
29 | Test() {
30 | std::cout << "Test():Acquire resources" << std::endl;
31 | pA.reset(new A);
32 |
33 | /*pA = new A;
34 | pInt = new int;
35 | pStr = new char[1000];
36 | pArr = new int[50000];*/
37 | }
38 | ~Test() {
39 | std::cout << "~Test():Release resources" << std::endl;
40 | throw std::runtime_error("Failed to initialize");
41 | /*delete pA;
42 | delete pInt;
43 | delete[]pStr;
44 | delete[] pArr;*/
45 | }
46 | };
47 |
48 | int main() {
49 | try {
50 | Test t;
51 | throw std::runtime_error{ "Exception" };
52 | }
53 | catch (std::runtime_error &ex) {
54 | std::cout << ex.what() << std::endl;
55 | }
56 | return 0;
57 | }
--------------------------------------------------------------------------------
/Section 10/Nested Exceptions/Exception Handling/Exception Handling.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Exception Handling", "Exception Handling\Exception Handling.vcxproj", "{3C30E739-6A6A-4E7B-8F62-6114DA5E61DA}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {3C30E739-6A6A-4E7B-8F62-6114DA5E61DA}.Debug|x64.ActiveCfg = Debug|x64
17 | {3C30E739-6A6A-4E7B-8F62-6114DA5E61DA}.Debug|x64.Build.0 = Debug|x64
18 | {3C30E739-6A6A-4E7B-8F62-6114DA5E61DA}.Debug|x86.ActiveCfg = Debug|Win32
19 | {3C30E739-6A6A-4E7B-8F62-6114DA5E61DA}.Debug|x86.Build.0 = Debug|Win32
20 | {3C30E739-6A6A-4E7B-8F62-6114DA5E61DA}.Release|x64.ActiveCfg = Release|x64
21 | {3C30E739-6A6A-4E7B-8F62-6114DA5E61DA}.Release|x64.Build.0 = Release|x64
22 | {3C30E739-6A6A-4E7B-8F62-6114DA5E61DA}.Release|x86.ActiveCfg = Release|Win32
23 | {3C30E739-6A6A-4E7B-8F62-6114DA5E61DA}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 10/Nested Exceptions/Exception Handling/Exception Handling/Exception Handling.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Section 11/Binary Files/FileIO-BinaryFiles/FileIO-BinaryFiles.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FileIO-BinaryFiles", "FileIO-BinaryFiles\FileIO-BinaryFiles.vcxproj", "{26A3B1D8-3BC5-469B-9112-8718325BCCA8}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {26A3B1D8-3BC5-469B-9112-8718325BCCA8}.Debug|x64.ActiveCfg = Debug|x64
17 | {26A3B1D8-3BC5-469B-9112-8718325BCCA8}.Debug|x64.Build.0 = Debug|x64
18 | {26A3B1D8-3BC5-469B-9112-8718325BCCA8}.Debug|x86.ActiveCfg = Debug|Win32
19 | {26A3B1D8-3BC5-469B-9112-8718325BCCA8}.Debug|x86.Build.0 = Debug|Win32
20 | {26A3B1D8-3BC5-469B-9112-8718325BCCA8}.Release|x64.ActiveCfg = Release|x64
21 | {26A3B1D8-3BC5-469B-9112-8718325BCCA8}.Release|x64.Build.0 = Release|x64
22 | {26A3B1D8-3BC5-469B-9112-8718325BCCA8}.Release|x86.ActiveCfg = Release|Win32
23 | {26A3B1D8-3BC5-469B-9112-8718325BCCA8}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 11/Binary Files/FileIO-BinaryFiles/FileIO-BinaryFiles/FileIO-BinaryFiles.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 11/Binary Files/FileIO-BinaryFiles/FileIO-BinaryFiles/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | struct Record {
5 | int id;
6 | char name[10];
7 | };
8 | void WriteRecord(Record *p) {
9 | std::ofstream binstream{ "records", std::ios::binary | std::ios::out };
10 | binstream.write((const char *)p, sizeof(Record));
11 | }
12 | Record GetRecord() {
13 | std::ifstream input{ "records", std::ios::binary | std::ios::in };
14 | Record r;
15 | input.read((char*)&r, sizeof(Record));
16 | return r;
17 | }
18 | int main() {
19 | Record r;
20 | r.id = 1001;
21 | strcpy_s(r.name,10, "Umar");
22 | WriteRecord(&r);
23 |
24 | Record r2 = GetRecord();
25 | std::cout << r2.id << ":" << r2.name << std::endl;
26 |
27 | //std::ofstream textstream{ "data" };
28 | //textstream << 12345678;
29 |
30 | //std::ofstream binstream{ "binary", std::ios::binary | std::ios::out };
31 | //int num{ 12345678 };
32 | //binstream.write((const char*)&num, sizeof(num));
33 | //num = 0;
34 | //binstream.close();
35 | //std::ifstream input{ "binary", std::ios::binary | std::ios::in };
36 | //input.read((char*)&num, sizeof(num));
37 |
38 | //std::cout << num << std::endl;
39 | return 0;
40 | }
--------------------------------------------------------------------------------
/Section 11/Binary Files/FileIO-BinaryFiles/FileIO-BinaryFiles/binary:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umarmlone/beg_mod_cpp/f1aec3fe477e1145fd97740b8286d95ed61605da/Section 11/Binary Files/FileIO-BinaryFiles/FileIO-BinaryFiles/binary
--------------------------------------------------------------------------------
/Section 11/Binary Files/FileIO-BinaryFiles/FileIO-BinaryFiles/binary.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umarmlone/beg_mod_cpp/f1aec3fe477e1145fd97740b8286d95ed61605da/Section 11/Binary Files/FileIO-BinaryFiles/FileIO-BinaryFiles/binary.bin
--------------------------------------------------------------------------------
/Section 11/Binary Files/FileIO-BinaryFiles/FileIO-BinaryFiles/data:
--------------------------------------------------------------------------------
1 | 12345678
--------------------------------------------------------------------------------
/Section 11/Binary Files/FileIO-BinaryFiles/FileIO-BinaryFiles/data.bin:
--------------------------------------------------------------------------------
1 | 12345678
--------------------------------------------------------------------------------
/Section 11/Binary Files/FileIO-BinaryFiles/FileIO-BinaryFiles/records.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umarmlone/beg_mod_cpp/f1aec3fe477e1145fd97740b8286d95ed61605da/Section 11/Binary Files/FileIO-BinaryFiles/FileIO-BinaryFiles/records.bin
--------------------------------------------------------------------------------
/Section 11/Error Handling/File IO/File IO/File IO.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Section 11/Error Handling/File IO/File IO/Header.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 |
6 | class Test {
7 | std::fstream fstream;
8 | std::ifstream ifstream;
9 | std::ofstream ofstream;
10 | std::istringstream istringstream;
11 | std::ostringstream ostringstream;
12 | std::stringstream str;
13 | };
--------------------------------------------------------------------------------
/Section 11/Error Handling/File IO/File IO/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | void Write() {
5 | std::ofstream out{"data.txt"};
6 | out << "Hello world" << std::endl;
7 | out << 10 << std::endl;
8 | out.close();
9 | }
10 | void Read() {
11 | std::ifstream input{ "data.txt" };
12 | //if (!input.is_open()) {
13 | // std::cout << "Could not open the file" << std::endl;
14 | // return;
15 | //}
16 | if (input.fail()) {
17 | std::cout << "Could not open the file" << std::endl;
18 | return;
19 | }
20 | std::string message;
21 | std::getline(input, message);
22 | int value{};
23 | input >> value;
24 | input >> value;
25 | if (input.eof()) {
26 | std::cout << "End of file encountered" << std::endl;
27 | }
28 | if (input.good()) {
29 | std::cout << "I/O operations are successful" << std::endl;
30 | }
31 | else {
32 | std::cout << "Some I/O operations failed" << std::endl;
33 | }
34 | input.setstate(std::ios::failbit);
35 | input.clear();
36 | input.close();
37 | std::cout << message << ":" << value << std::endl;
38 | }
39 | int main() {
40 | Write();
41 | Read();
42 | return 0;
43 | }
--------------------------------------------------------------------------------
/Section 11/Error Handling/File IO/File IO/data.txt:
--------------------------------------------------------------------------------
1 | Hello world
2 | 10
3 |
--------------------------------------------------------------------------------
/Section 12.5/Binder/Binder/Binder.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 12.5/Binder/Binder/Binder.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Section 12.5/Binder/Binder/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int Subtract(int x, int y) {
5 | return x - y;
6 | }
7 | void Print(const char *p) {
8 | std::cout << p << '\n' ;
9 | }
10 | struct GreaterThan {
11 | bool operator()(int x,int y)const {
12 | return x > y ;
13 | }
14 | };
15 | int Operation(int x,int y, std::function callback) {
16 | return callback(x,y) ;
17 | }
18 | int Accumulate(int x,int y, int z) {
19 | return x + y + z ;
20 | }
21 | int main() {
22 | using namespace std::placeholders ;
23 | //std::function f = std::bind(Subtract,std::placeholders::_2,std::placeholders::_1) ;
24 | //auto f = std::bind(Subtract,_1, 5) ;
25 | auto f = [](auto && x) {
26 | return Subtract(std::forward(x),5) ;
27 | } ;
28 | std::cout << f(8) << '\n' ; //Subtract(2,3) ;
29 |
30 | //auto gt = std::bind(GreaterThan{}, _2, _1) ;
31 | //C++20 template type parameters in lambda
32 | auto gt = [](T&& x,T&& y) {
33 | return GreaterThan{}(std::forward(y), std::forward(x)) ;
34 | } ;
35 | std::cout << gt(6,2) << '\n' ; //operator()(2,6)
36 |
37 | //auto acc = std::bind(Accumulate,_1, _2, 0) ;
38 | //C++20 template type parameters in lambda
39 | auto acc = [](T&& x,T&& y) {
40 | return Accumulate(std::forward(x),std::forward(y), 0) ;
41 | } ;
42 | std::cout << Operation(8,5, acc) << '\n';
43 |
44 | }
--------------------------------------------------------------------------------
/Section 12.5/Function/Function/Function.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 12.5/Function/Function/Function.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Section 12.5/Function/Function/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | int Square(int x) {
4 | return x * x;
5 | }
6 | int Add(int x, int y) {
7 | return x + y;
8 | }
9 | int Subtract(int x, int y) {
10 | return x - y;
11 | }
12 | struct Max {
13 | int operator()(int x,int y)const {
14 | return x > y ? x : y ;
15 | }
16 | };
17 | int Operation(int x,int y, std::function callback) {
18 | return callback(x,y) ;
19 | }
20 | int main() {
21 | try {
22 | /*std::function f1 ;
23 | if(f1) {
24 | std::cout << f1(3) << std::endl ;
25 | }else {
26 | std::cout << "No target to invoke!\n" ;
27 | }
28 | Max m{} ;
29 | std::function f2 = m ;
30 | std::cout << f2(3,5) << '\n' ;
31 |
32 | std::function f3 = [](int x){return x % 2 == 0;} ;
33 | std::cout << "IsEven?" << f3(4) << '\n' ;*/
34 | std::function f1 = Add ;
35 | std::cout << Operation(3,5, f1) << '\n' ;
36 | f1 = Subtract ;
37 | std::cout << Operation(3,5, f1) << '\n' ;
38 | std::cout << Operation(3,5, [](int x,int y){return x*y;}) << '\n' ;
39 |
40 | }
41 | catch (const std::exception& ex) {
42 | std::cout << "Exception -> " << ex.what() << '\n';
43 | }
44 | }
--------------------------------------------------------------------------------
/Section 12/Aliases/Aliases/Aliases.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Aliases", "Aliases\Aliases.vcxproj", "{01600489-71F9-41A4-B25D-E56AE362F0ED}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {01600489-71F9-41A4-B25D-E56AE362F0ED}.Debug|x64.ActiveCfg = Debug|x64
17 | {01600489-71F9-41A4-B25D-E56AE362F0ED}.Debug|x64.Build.0 = Debug|x64
18 | {01600489-71F9-41A4-B25D-E56AE362F0ED}.Debug|x86.ActiveCfg = Debug|Win32
19 | {01600489-71F9-41A4-B25D-E56AE362F0ED}.Debug|x86.Build.0 = Debug|Win32
20 | {01600489-71F9-41A4-B25D-E56AE362F0ED}.Release|x64.ActiveCfg = Release|x64
21 | {01600489-71F9-41A4-B25D-E56AE362F0ED}.Release|x64.Build.0 = Release|x64
22 | {01600489-71F9-41A4-B25D-E56AE362F0ED}.Release|x86.ActiveCfg = Release|Win32
23 | {01600489-71F9-41A4-B25D-E56AE362F0ED}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 12/Aliases/Aliases/Aliases/Aliases.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 12/Aliases/Aliases/Aliases/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | const char * GetErrorMessage(int errorNo) {
6 | return "Empty";
7 | }
8 | //typedef const char *(*PFN)(int);
9 | using PFN = const char *(*)(int);
10 | void ShowError(PFN pfn){
11 |
12 | }
13 | //typedef std::vector < std::list> Names;
14 |
15 | //template
16 | //using Names = std::vector>;
17 |
18 | using Names = std::vector>;
19 |
20 | int main() {
21 | Names names;
22 | Names nnames;
23 |
24 | PFN pfn = GetErrorMessage;
25 | ShowError(pfn);
26 | return 0;
27 | }
28 |
--------------------------------------------------------------------------------
/Section 12/Basics/Basics.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Basics", "Basics\Basics.vcxproj", "{2622286E-16A7-4B71-A4AC-E0FB4469A82D}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {2622286E-16A7-4B71-A4AC-E0FB4469A82D}.Debug|x64.ActiveCfg = Debug|x64
17 | {2622286E-16A7-4B71-A4AC-E0FB4469A82D}.Debug|x64.Build.0 = Debug|x64
18 | {2622286E-16A7-4B71-A4AC-E0FB4469A82D}.Debug|x86.ActiveCfg = Debug|Win32
19 | {2622286E-16A7-4B71-A4AC-E0FB4469A82D}.Debug|x86.Build.0 = Debug|Win32
20 | {2622286E-16A7-4B71-A4AC-E0FB4469A82D}.Release|x64.ActiveCfg = Release|x64
21 | {2622286E-16A7-4B71-A4AC-E0FB4469A82D}.Release|x64.Build.0 = Release|x64
22 | {2622286E-16A7-4B71-A4AC-E0FB4469A82D}.Release|x86.ActiveCfg = Release|Win32
23 | {2622286E-16A7-4B71-A4AC-E0FB4469A82D}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 12/Basics/Basics/Basics.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Source Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Section 12/Class Exp Spec - II/Class Template ExSpecialization/Class Template ExSpecialization/Class Template ExSpecialization.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 12/Class Templates/Class Templates/Class Templates.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Class Templates", "Class Templates\Class Templates.vcxproj", "{775F7529-67F5-4ED6-AAA4-55C6697A6419}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {775F7529-67F5-4ED6-AAA4-55C6697A6419}.Debug|x64.ActiveCfg = Debug|x64
17 | {775F7529-67F5-4ED6-AAA4-55C6697A6419}.Debug|x64.Build.0 = Debug|x64
18 | {775F7529-67F5-4ED6-AAA4-55C6697A6419}.Debug|x86.ActiveCfg = Debug|Win32
19 | {775F7529-67F5-4ED6-AAA4-55C6697A6419}.Debug|x86.Build.0 = Debug|Win32
20 | {775F7529-67F5-4ED6-AAA4-55C6697A6419}.Release|x64.ActiveCfg = Release|x64
21 | {775F7529-67F5-4ED6-AAA4-55C6697A6419}.Release|x64.Build.0 = Release|x64
22 | {775F7529-67F5-4ED6-AAA4-55C6697A6419}.Release|x86.ActiveCfg = Release|Win32
23 | {775F7529-67F5-4ED6-AAA4-55C6697A6419}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 12/Class Templates/Class Templates/Class Templates/Class Templates.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 12/Partial Spec/Class Template ParSpecializatoin/Class Template ParSpecializatoin/Class Template ParSpecializatoin.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 12/Perfect Forwarding - II/Perfect forwarding/Perfect forwarding/Integer.cpp:
--------------------------------------------------------------------------------
1 | #include "Integer.h"
2 | #include
3 | Integer::Integer() {
4 | std::cout << "Integer()" << std::endl;
5 | m_pInt = new int(0);
6 | }
7 |
8 | Integer::Integer(int value) {
9 | std::cout << "Integer(int)" << std::endl;
10 | m_pInt = new int(value);
11 | }
12 |
13 | Integer::Integer(const Integer & obj) {
14 | std::cout << "Integer(const Integer&)" << std::endl;
15 | m_pInt = new int(*obj.m_pInt);
16 | }
17 |
18 | Integer::Integer(Integer && obj) {
19 | std::cout << "Integer(int&&)" << std::endl;
20 | m_pInt = obj.m_pInt;
21 | obj.m_pInt = nullptr;
22 | }
23 |
24 | int Integer::GetValue() const {
25 | return *m_pInt;
26 | }
27 |
28 | void Integer::SetValue(int value) {
29 | *m_pInt = value;
30 | }
31 |
32 | Integer::~Integer() {
33 | std::cout << "~Integer()" << std::endl;
34 | delete m_pInt;
35 | }
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/Section 12/Perfect Forwarding - II/Perfect forwarding/Perfect forwarding/Integer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | class Integer {
4 | int *m_pInt;
5 | public:
6 | //Default constructor
7 | Integer();
8 |
9 | //Parameterized constructor
10 | Integer(int value);
11 |
12 | //Copy constructor
13 | Integer(const Integer &obj);
14 |
15 | //Move constructor
16 | Integer(Integer &&obj);
17 |
18 | int GetValue()const;
19 | void SetValue(int value);
20 | ~Integer();
21 |
22 | };
23 |
--------------------------------------------------------------------------------
/Section 12/Perfect Forwarding - II/Perfect forwarding/Perfect forwarding/Perfect forwarding.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 |
26 |
27 | Header Files
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Section 12/Perfect Forwarding - II/Perfect forwarding/Perfect forwarding/main.cpp:
--------------------------------------------------------------------------------
1 | #include "Integer.h"
2 | #include
3 | #include
4 | class Employee {
5 | std::string m_Name;
6 | Integer m_Id;
7 | public:
8 | //Employee(const std::string &name, const Integer &id) :
9 | // m_Name{ name },
10 | // m_Id{ id } {
11 | // std::cout << "Employee(const std::string &name, const Integer &id)" << std::endl;
12 | //}
13 | template
14 | Employee(T1 &&name, T2 &&id) :
15 | m_Name{ std::forward(name) },
16 | m_Id{ std::forward(id) } {
17 | std::cout << "Employee(std::string &&name, Integer &&id)" << std::endl;
18 |
19 | }
20 | };
21 | template
22 | Employee *Create(T1 && a, T2 &&b) {
23 | return new Employee(std::forward(a), std::forward(b));
24 | }
25 | int main() {
26 | //Employee emp1{ "Umar", Integer{100} };
27 | /*std::string name = "Umar";
28 | Employee emp2{ name, 100 };
29 | Integer val{ 100 };
30 | Employee emp3{ std::string{"Umar"}, val };*/
31 | auto emp = Create("Umar", Integer{ 100 });
32 | return 0;
33 | }
--------------------------------------------------------------------------------
/Section 12/StaticAssert/static_assert.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | template
4 | T Divide(T a, T b){
5 | static_assert(std::is_floating_point::value, "Only floating point type supported") ;
6 | if(std::is_floating_point::value == false){
7 | std::cout << "Use floating point types only\n" ;
8 | return 0 ;
9 | }
10 | return a/b ;
11 | }
12 | int main(){
13 | std::cout
14 | << std::boolalpha
15 | << "Is integer?" << std::is_integral::value << std::endl;
16 |
17 | std::cout << Divide(5.1, 7.3) << std::endl ;
18 | }
--------------------------------------------------------------------------------
/Section 12/TypeTraits/traits.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | template
5 | T Divide(T a, T b) {
6 | if(std::is_floating_point::value == false) {
7 | std::cout << "Use floating point types only\n" ;
8 | return 0 ;
9 | }
10 | return a / b ;
11 | }
12 | template
13 | void Check(T &&) {
14 | std::cout << std::boolalpha ;
15 | std::cout << "Is reference?" << std::is_reference::value << std::endl ;
16 | std::cout << "After removing:" <<
17 | std::is_reference::type>::value << std::endl;
18 | }
19 | int main() {
20 | Check(5) ;
21 | int value{} ;
22 | Check(value) ;
23 | }
--------------------------------------------------------------------------------
/Section 12/Variadic Templates - II/Variadic Templates/Variadic Templates/Integer.cpp:
--------------------------------------------------------------------------------
1 | #include "Integer.h"
2 | #include
3 | Integer::Integer() {
4 | std::cout << "Integer()" << std::endl;
5 | m_pInt = new int(0);
6 | }
7 |
8 | Integer::Integer(int value) {
9 | std::cout << "Integer(int)" << std::endl;
10 | m_pInt = new int(value);
11 | }
12 |
13 | Integer::Integer(const Integer & obj) {
14 | std::cout << "Integer(const Integer&)" << std::endl;
15 | m_pInt = new int(*obj.m_pInt);
16 | }
17 |
18 | Integer::Integer(Integer && obj) {
19 | std::cout << "Integer(int&&)" << std::endl;
20 | m_pInt = obj.m_pInt;
21 | obj.m_pInt = nullptr;
22 | }
23 |
24 | int Integer::GetValue() const {
25 | return *m_pInt;
26 | }
27 |
28 | void Integer::SetValue(int value) {
29 | *m_pInt = value;
30 | }
31 |
32 | Integer::~Integer() {
33 | std::cout << "~Integer()" << std::endl;
34 | delete m_pInt;
35 | }
36 |
37 | std::ostream & operator<<(std::ostream & out, const Integer & obj)
38 | {
39 | out << *obj.m_pInt;
40 | return out;
41 | }
42 |
--------------------------------------------------------------------------------
/Section 12/Variadic Templates - II/Variadic Templates/Variadic Templates/Integer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | class Integer {
4 | int *m_pInt;
5 | public:
6 | //Default constructor
7 | Integer();
8 | //Parameterized constructor
9 | Integer(int value);
10 | //Copy constructor
11 | Integer(const Integer &obj);
12 | //Move constructor
13 | Integer(Integer &&obj);
14 | int GetValue()const;
15 | void SetValue(int value);
16 | ~Integer();
17 |
18 | friend std::ostream & operator <<(std::ostream & out, const Integer &obj);
19 | };
20 |
--------------------------------------------------------------------------------
/Section 12/Variadic Templates - II/Variadic Templates/Variadic Templates/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "Integer.h"
3 | //Works only for homogenous data types
4 | //template
5 | //void Print(std::initializer_list args) {
6 | // for (const auto &x : args) {
7 | // std::cout << x << " ";
8 | // }
9 | //}
10 |
11 | void Print(){
12 | std::cout << std::endl;
13 | }
14 |
15 | //Template parameter pack
16 | template
17 | //Function parameter pack
18 | void Print(T &&a, Params&&... args) {
19 | //std::cout << sizeof...(args) << std::endl;
20 | //std::cout << sizeof...(Params) << std::endl;
21 | std::cout << a;
22 | if (sizeof...(args) != 0) {
23 | std::cout << ",";
24 | }
25 | //We can forward a function parameter pack
26 | Print(std::forward(args)...);
27 | }
28 |
29 |
30 | int main() {
31 | //Print({ 1,2.5,3,4 });
32 | //Print(1, 2.5, 3, "4");
33 | Integer val{ 1 };
34 | Print(0, val, Integer{ 2 });
35 | return 0;
36 | }
37 | /*
38 | 1. Print(1, 2.5, 3, "4") ;
39 | 2. Print(2.5, 3, "4") ;
40 | 3. Print(3, "4") ;
41 | 4. Print("4") ;
42 | 5. Print() ;
43 | */
44 |
--------------------------------------------------------------------------------
/Section 12/Variadic Templates - II/Variadic Templates/Variadic Templates/Variadic Templates.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 |
26 |
27 | Header Files
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Section 13/Capture List/CaptureList/CaptureList.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CaptureList", "CaptureList\CaptureList.vcxproj", "{410963AC-36A0-452B-9A2F-5354B19DF018}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {410963AC-36A0-452B-9A2F-5354B19DF018}.Debug|x64.ActiveCfg = Debug|x64
17 | {410963AC-36A0-452B-9A2F-5354B19DF018}.Debug|x64.Build.0 = Debug|x64
18 | {410963AC-36A0-452B-9A2F-5354B19DF018}.Debug|x86.ActiveCfg = Debug|Win32
19 | {410963AC-36A0-452B-9A2F-5354B19DF018}.Debug|x86.Build.0 = Debug|Win32
20 | {410963AC-36A0-452B-9A2F-5354B19DF018}.Release|x64.ActiveCfg = Release|x64
21 | {410963AC-36A0-452B-9A2F-5354B19DF018}.Release|x64.Build.0 = Release|x64
22 | {410963AC-36A0-452B-9A2F-5354B19DF018}.Release|x86.ActiveCfg = Release|Win32
23 | {410963AC-36A0-452B-9A2F-5354B19DF018}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 13/Capture List/CaptureList/CaptureList/CaptureList.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 13/Function Objects/Function Objects/Function Objects.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Function Objects", "Function Objects\Function Objects.vcxproj", "{2F7F4586-DA79-4429-B2A9-5407F02C84B0}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {2F7F4586-DA79-4429-B2A9-5407F02C84B0}.Debug|x64.ActiveCfg = Debug|x64
17 | {2F7F4586-DA79-4429-B2A9-5407F02C84B0}.Debug|x64.Build.0 = Debug|x64
18 | {2F7F4586-DA79-4429-B2A9-5407F02C84B0}.Debug|x86.ActiveCfg = Debug|Win32
19 | {2F7F4586-DA79-4429-B2A9-5407F02C84B0}.Debug|x86.Build.0 = Debug|Win32
20 | {2F7F4586-DA79-4429-B2A9-5407F02C84B0}.Release|x64.ActiveCfg = Release|x64
21 | {2F7F4586-DA79-4429-B2A9-5407F02C84B0}.Release|x64.Build.0 = Release|x64
22 | {2F7F4586-DA79-4429-B2A9-5407F02C84B0}.Release|x86.ActiveCfg = Release|Win32
23 | {2F7F4586-DA79-4429-B2A9-5407F02C84B0}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 13/Function Objects/Function Objects/Function Objects/Function Objects.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 13/Function Objects/Function Objects/Function Objects/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | //using Comparator = bool(*)(int, int);
3 | template
4 | void Sort(T(&arr)[size], Comparator comp) {
5 | for (int i = 0; i < size-1; ++i) {
6 | for (int j = 0; j < size - 1; ++j) {
7 | if (comp(arr[j], arr[j + 1])) {
8 | T temp = std::move(arr[j]);
9 | arr[j] = std::move(arr[j + 1]);
10 | arr[j + 1] = std::move(temp);
11 | }
12 | }
13 | }
14 | }
15 | //Function pointers as comparators
16 | bool Comp(int x, int y) {
17 | return x > y;
18 | }
19 | bool Comp1(int x, int y) {
20 | return x < y;
21 | }
22 |
23 |
24 | //Function Object as comparator
25 | struct Comp2 {
26 | bool operator()(int x, int y) {
27 | return x > y;
28 | }
29 | };
30 | int main() {
31 | Comp(3, 5);
32 | Comp2 comp;
33 | comp(3, 5);//comp.operator()(3,5) ;
34 | int arr[]{ 1,6,8,4,0 };
35 | for (auto x : arr) {
36 | std::cout << x << " ";
37 | }
38 | std::cout << std::endl;
39 | Sort(arr, comp);
40 | for (auto x : arr) {
41 | std::cout << x << " ";
42 | }
43 | std::cout << std::endl;
44 | return 0;
45 | }
--------------------------------------------------------------------------------
/Section 13/Lambda Basics/Lambda Basics/Lambda Basics.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lambda Basics", "Lambda Basics\Lambda Basics.vcxproj", "{386CC69B-8C5A-4F59-8A0B-F04FF283EAD5}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {386CC69B-8C5A-4F59-8A0B-F04FF283EAD5}.Debug|x64.ActiveCfg = Debug|x64
17 | {386CC69B-8C5A-4F59-8A0B-F04FF283EAD5}.Debug|x64.Build.0 = Debug|x64
18 | {386CC69B-8C5A-4F59-8A0B-F04FF283EAD5}.Debug|x86.ActiveCfg = Debug|Win32
19 | {386CC69B-8C5A-4F59-8A0B-F04FF283EAD5}.Debug|x86.Build.0 = Debug|Win32
20 | {386CC69B-8C5A-4F59-8A0B-F04FF283EAD5}.Release|x64.ActiveCfg = Release|x64
21 | {386CC69B-8C5A-4F59-8A0B-F04FF283EAD5}.Release|x64.Build.0 = Release|x64
22 | {386CC69B-8C5A-4F59-8A0B-F04FF283EAD5}.Release|x86.ActiveCfg = Release|Win32
23 | {386CC69B-8C5A-4F59-8A0B-F04FF283EAD5}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 13/Lambda Basics/Lambda Basics/Lambda Basics/Lambda Basics.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 13/Lambda Basics/Lambda Basics/Lambda Basics/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | //Possible implementation of a lambda expression as a function object
3 | template
4 | struct Unnamed {
5 | T operator()(T x, T y)const {
6 | return x + y;
7 | }
8 | };
9 | int main() {
10 | //Compiler automatically creates a function object
11 | auto fn = []() {
12 | std::cout << "Welcome to Lambda expressions" << std::endl ;
13 | };
14 | fn();
15 | std::cout << typeid(fn).name() << std::endl;
16 | //Generic/polymorphic lambda
17 | //
18 | auto sum = [](auto x, auto y)/*mutable*/ /*noexcept*/(false){
19 | return x + y; // ^^^^ ^^^^
20 | };
21 | Unnamed n;
22 | std::cout << "Sum is:" << sum(5.5f, 2.2f) << std::endl;
23 | return 0;
24 | }
--------------------------------------------------------------------------------
/Section 14/STL/Algorithms.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umarmlone/beg_mod_cpp/f1aec3fe477e1145fd97740b8286d95ed61605da/Section 14/STL/Algorithms.zip
--------------------------------------------------------------------------------
/Section 14/STL/Algorithms/Algorithms.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Algorithms", "Algorithms\Algorithms.vcxproj", "{4777C8D0-B173-4893-B0E6-FC1207F1242C}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {4777C8D0-B173-4893-B0E6-FC1207F1242C}.Debug|x64.ActiveCfg = Debug|x64
17 | {4777C8D0-B173-4893-B0E6-FC1207F1242C}.Debug|x64.Build.0 = Debug|x64
18 | {4777C8D0-B173-4893-B0E6-FC1207F1242C}.Debug|x86.ActiveCfg = Debug|Win32
19 | {4777C8D0-B173-4893-B0E6-FC1207F1242C}.Debug|x86.Build.0 = Debug|Win32
20 | {4777C8D0-B173-4893-B0E6-FC1207F1242C}.Release|x64.ActiveCfg = Release|x64
21 | {4777C8D0-B173-4893-B0E6-FC1207F1242C}.Release|x64.Build.0 = Release|x64
22 | {4777C8D0-B173-4893-B0E6-FC1207F1242C}.Release|x86.ActiveCfg = Release|Win32
23 | {4777C8D0-B173-4893-B0E6-FC1207F1242C}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 14/STL/Algorithms/Algorithms/Algorithms.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 14/STL/AssociativeContainers.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umarmlone/beg_mod_cpp/f1aec3fe477e1145fd97740b8286d95ed61605da/Section 14/STL/AssociativeContainers.zip
--------------------------------------------------------------------------------
/Section 14/STL/AssociativeContainers/AssociativeContainers.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AssociativeContainers", "AssociativeContainers\AssociativeContainers.vcxproj", "{AA803F94-C51A-45AA-B5B0-BCBEA34B441E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {AA803F94-C51A-45AA-B5B0-BCBEA34B441E}.Debug|x64.ActiveCfg = Debug|x64
17 | {AA803F94-C51A-45AA-B5B0-BCBEA34B441E}.Debug|x64.Build.0 = Debug|x64
18 | {AA803F94-C51A-45AA-B5B0-BCBEA34B441E}.Debug|x86.ActiveCfg = Debug|Win32
19 | {AA803F94-C51A-45AA-B5B0-BCBEA34B441E}.Debug|x86.Build.0 = Debug|Win32
20 | {AA803F94-C51A-45AA-B5B0-BCBEA34B441E}.Release|x64.ActiveCfg = Release|x64
21 | {AA803F94-C51A-45AA-B5B0-BCBEA34B441E}.Release|x64.Build.0 = Release|x64
22 | {AA803F94-C51A-45AA-B5B0-BCBEA34B441E}.Release|x86.ActiveCfg = Release|Win32
23 | {AA803F94-C51A-45AA-B5B0-BCBEA34B441E}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 14/STL/AssociativeContainers/AssociativeContainers/AssociativeContainers.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 14/STL/ContainerChanges/ContainerChanges/ContainerChanges.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 |
26 |
27 | Header Files
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Section 14/STL/ContainerChanges/ContainerChanges/Integer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | class Integer {
4 | int *m_pInt;
5 | public:
6 | //Default constructor
7 | Integer();
8 | //Parameterized constructor
9 | Integer(int value);
10 | //Copy constructor
11 | Integer(const Integer &obj);
12 | //Move constructor
13 | Integer(Integer &&obj)noexcept;
14 | int GetValue()const;
15 | void SetValue(int value);
16 | ~Integer();
17 | Integer & operator ++();
18 | Integer operator ++(int);
19 | bool operator ==(const Integer &a)const;
20 |
21 | //Copy assignment
22 | Integer & operator =(const Integer &a);
23 | //Move assignment
24 | Integer & operator =(Integer &&a)noexcept;
25 | Integer operator +(const Integer & a)const;
26 |
27 | void operator ()();
28 | };
29 | Integer operator +(int x, const Integer &y);
30 | std::ostream & operator <<(std::ostream & out, const Integer &a);
31 | std::istream & operator >> (std::istream &input, Integer &a);
--------------------------------------------------------------------------------
/Section 14/STL/SequenceContainers.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umarmlone/beg_mod_cpp/f1aec3fe477e1145fd97740b8286d95ed61605da/Section 14/STL/SequenceContainers.zip
--------------------------------------------------------------------------------
/Section 14/STL/SequenceContainers/SequenceContainers.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SequenceContainers", "SequenceContainers\SequenceContainers.vcxproj", "{86618899-1E9A-41CB-8124-D516EE7215BD}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {86618899-1E9A-41CB-8124-D516EE7215BD}.Debug|x64.ActiveCfg = Debug|x64
17 | {86618899-1E9A-41CB-8124-D516EE7215BD}.Debug|x64.Build.0 = Debug|x64
18 | {86618899-1E9A-41CB-8124-D516EE7215BD}.Debug|x86.ActiveCfg = Debug|Win32
19 | {86618899-1E9A-41CB-8124-D516EE7215BD}.Debug|x86.Build.0 = Debug|Win32
20 | {86618899-1E9A-41CB-8124-D516EE7215BD}.Release|x64.ActiveCfg = Release|x64
21 | {86618899-1E9A-41CB-8124-D516EE7215BD}.Release|x64.Build.0 = Release|x64
22 | {86618899-1E9A-41CB-8124-D516EE7215BD}.Release|x86.ActiveCfg = Release|Win32
23 | {86618899-1E9A-41CB-8124-D516EE7215BD}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 14/STL/SequenceContainers/SequenceContainers/SequenceContainers.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 14/STL/UnorderedContainers.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umarmlone/beg_mod_cpp/f1aec3fe477e1145fd97740b8286d95ed61605da/Section 14/STL/UnorderedContainers.zip
--------------------------------------------------------------------------------
/Section 14/STL/UnorderedContainers/UnorderedContainers.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnorderedContainers", "UnorderedContainers\UnorderedContainers.vcxproj", "{0EEA4101-2FFD-4E1D-9C14-FFDEA901A663}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {0EEA4101-2FFD-4E1D-9C14-FFDEA901A663}.Debug|x64.ActiveCfg = Debug|x64
17 | {0EEA4101-2FFD-4E1D-9C14-FFDEA901A663}.Debug|x64.Build.0 = Debug|x64
18 | {0EEA4101-2FFD-4E1D-9C14-FFDEA901A663}.Debug|x86.ActiveCfg = Debug|Win32
19 | {0EEA4101-2FFD-4E1D-9C14-FFDEA901A663}.Debug|x86.Build.0 = Debug|Win32
20 | {0EEA4101-2FFD-4E1D-9C14-FFDEA901A663}.Release|x64.ActiveCfg = Release|x64
21 | {0EEA4101-2FFD-4E1D-9C14-FFDEA901A663}.Release|x64.Build.0 = Release|x64
22 | {0EEA4101-2FFD-4E1D-9C14-FFDEA901A663}.Release|x86.ActiveCfg = Release|Win32
23 | {0EEA4101-2FFD-4E1D-9C14-FFDEA901A663}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/Section 14/STL/UnorderedContainers/UnorderedContainers/UnorderedContainers.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 15/Async/Async/Async.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 15/Async/Async/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | return 0;
5 | }
--------------------------------------------------------------------------------
/Section 15/Async/Async/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | int Operation(int count) {
6 | using namespace std::chrono_literals;
7 | int sum{};
8 | for (int i = 0; i < count; ++i) {
9 | sum += i;
10 | std::cout << '.';
11 | std::this_thread::sleep_for(300ms);//std::chrono::seconds(1)
12 | }
13 | return sum;
14 | }
15 | int main() {
16 | using namespace std::chrono_literals ;
17 | std::future result = std::async(std::launch::async, Operation, 10);
18 | std::this_thread::sleep_for(1s) ;
19 | std::cout << "main() thread continues execution...\n";
20 | if (result.valid()) {
21 | auto timepoint = std::chrono::system_clock::now() ;
22 | timepoint += 1s ;
23 | auto status = result.wait_until(timepoint) ;
24 | //auto status = result.wait_for(4s) ;
25 | switch(status) {
26 | case std::future_status::deferred:
27 | std::cout << "Task is synchronous\n" ;
28 | break ;
29 | case std::future_status::ready:
30 | std::cout << "Result is ready\n" ;
31 | break ;
32 | case std::future_status::timeout:
33 | std::cout << "Task is still running\n" ;
34 | break ;
35 | }
36 | //result.wait() ;
37 | //Operation(10) ;
38 | auto sum = result.get();
39 | std::cout << sum << std::endl;
40 | }
41 | }
--------------------------------------------------------------------------------
/Section 15/PromiseFuture/PromiseFuture/PromiseFuture.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 15/PromiseFuture/PromiseFuture/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | int Operation(std::promise & data) {
6 | using namespace std::chrono_literals;
7 | auto f = data.get_future() ;
8 | try {
9 | std::cout << "[Task] Waiting for count\n";
10 | auto count = f.get();
11 | std::cout << "[Task] Count acquired.\n";
12 | int sum{};
13 | for (int i = 0; i < count; ++i) {
14 | sum += i;
15 | std::cout << '.';
16 | std::this_thread::sleep_for(300ms);//std::chrono::seconds(1)
17 | }
18 | return sum;
19 | }catch(std::exception &ex) {
20 | std::cout << "[Task] Exception:" << ex.what() << std::endl;
21 | }
22 | }
23 | int main() {
24 | using namespace std::chrono_literals ;
25 | std::promise data ;
26 | std::future result = std::async(std::launch::async, Operation, std::ref(data));
27 | std::this_thread::sleep_for(1s) ;
28 | std::cout << "[main] Setting the data in promise\n";
29 | try {
30 | throw std::runtime_error{"Data not available"} ;
31 | data.set_value(10);
32 | if (result.valid()) {
33 | auto sum = result.get();
34 | std::cout << sum << std::endl;
35 | }
36 | }catch(std::exception &ex) {
37 | data.set_exception(std::make_exception_ptr(ex)) ;
38 | }
39 |
40 | }
--------------------------------------------------------------------------------
/Section 15/Sharing Data/Sharing Data/Sharing Data.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 15/Sharing Data/Sharing Data/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | std::list g_Data;
7 | const int SIZE = 10000;
8 | std::mutex g_Mutex;
9 | void Download() {
10 | for (int i = 0; i < SIZE; ++i) {
11 | //Use std::lock_guard to lock a mutex (RAII)
12 | std::lock_guard mtx(g_Mutex);
13 | g_Data.push_back(i);
14 | if (i == 500)
15 | return;
16 | }
17 | }
18 | void Download2() {
19 | for (int i = 0; i < SIZE; ++i) {
20 | std::lock_guard mtx(g_Mutex);
21 | g_Data.push_back(i);
22 | }
23 | }
24 | int main() {
25 | std::thread thDownloader(Download);
26 | std::thread thDownloader2(Download2);
27 | thDownloader.join();
28 | thDownloader2.join();
29 | std::cout << g_Data.size() << std::endl;
30 | return 0;
31 | }
--------------------------------------------------------------------------------
/Section 15/ThreadClass/ThreadClass/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | void Process() {
5 | //std::cout << "Threadid:" << std::this_thread::get_id() << std::endl;
6 | for (int i = 0; i < 10; ++i) {
7 | std::this_thread::sleep_for(std::chrono::seconds(1));
8 | std::cout << i << ' ';
9 | }
10 | }
11 |
12 | int main() {
13 | std::thread t1(Process);
14 | //Returns the native type of the thread
15 | //On Linux, the native type is pthread_t
16 | HANDLE handle = t1.native_handle();
17 | SetThreadDescription(handle, L"MyThread");
18 | auto id = t1.get_id();
19 | std::cout << "t1.get_id()" << id << std::endl;
20 |
21 | int cores = std::thread::hardware_concurrency();
22 |
23 | std::cout << "Cores:" << cores << std::endl;
24 | t1.join();
25 | return 0;
26 | }
--------------------------------------------------------------------------------
/Section 15/ThreadClass/ThreadClass/ThreadClass.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 15/Threads/Threads/Source.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | std::list g_Data;
6 | const int SIZE = 5000000;
7 | class String {
8 | public:
9 | String() {
10 | std::cout << "String()" << std::endl;
11 | }
12 | String(const String &) {
13 | std::cout << "String(const String&)" << std::endl;
14 | }
15 | String & operator=(const String&) {
16 | std::cout << "operator=(const String&)" << std::endl;
17 |
18 | return *this;
19 | }
20 | ~String() {
21 | std::cout << "~String()" << std::endl;
22 | }
23 | };
24 | void Download(const String &file) {
25 | //std::cout << "[Downloader]Started download of file :" << file << std::endl;
26 | for (int i = 0; i < SIZE; ++i) {
27 | g_Data.push_back(i);
28 | }
29 | std::cout << "[Downloader]Finished download" << std::endl;
30 | }
31 | int main() {
32 | String file;
33 | std::cout << "[main]User started an operation" << std::endl;
34 | //use std::ref and std::cref to pass arguments as reference & const reference, respectively
35 | std::thread thDownloader(Download,std::cref(file) );
36 | //thDownloader.detach();
37 |
38 | std::cout << "[main]User started another operation" << std::endl;
39 | //Always check before joining a thread
40 | if (thDownloader.joinable()) {
41 | thDownloader.join() ;
42 | }
43 | //system("Pause");
44 | return 0;
45 | }
--------------------------------------------------------------------------------
/Section 15/Threads/Threads/Threads.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Section 16/attributes/attributes.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #ifdef __has_include
3 | #if __has_include()
4 | #define FS 1
5 | #include
6 | #endif
7 | #endif
8 |
9 |
10 | //[[deprecated("Don't use")]]
11 | //void Foo() {
12 | //
13 | //}
14 | //
15 | //class [[deprecated("Not allowed")]] A{
16 | //
17 | //} ;
18 | //
19 | //namespace [[deprecated("Not allowed")]] Old{
20 | //}
21 |
22 | #pragma message("DO NOT USE THIS FILE")
23 | class [[nodiscard]] Test{
24 | };
25 | [[nodiscard]]
26 | int &Square(int x) {
27 | int *p = new int{x} ;
28 | return *p;
29 | }
30 | Test Create() {
31 | return Test{} ;
32 | }
33 |
34 |
35 | [[deprecated("Use the template version instead")]]
36 | [[nodiscard]]
37 | int * CreateIntArray(size_t size) {
38 | return new int[size] ;
39 | }
40 |
41 | template
42 | [[nodiscard]] T * CreateArray(size_t size) {
43 | return new T[size] ;
44 | }
45 |
46 | int main() {
47 | //CreateIntArray(5) ;
48 | //CreateArray(3) ;
49 | }
50 |
--------------------------------------------------------------------------------
/Section 16/evaluationorder/evaluationorder.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | class EvaluationOrder {
4 | public:
5 | EvaluationOrder& First(int) {
6 | std::cout << __FUNCSIG__ << std::endl;
7 | return *this;
8 | }
9 | EvaluationOrder& Second(int) {
10 | std::cout << __FUNCSIG__ << std::endl;
11 | return *this;
12 | }
13 | };
14 | int FirstSubExpression(int) {
15 | std::cout << __FUNCSIG__ << std::endl;
16 | return 0 ;
17 |
18 | }
19 | int SecondSubExpression(int) {
20 | std::cout << __FUNCSIG__ << std::endl;
21 | return 0 ;
22 |
23 | }
24 | int main() {
25 | EvaluationOrder eo ;
26 | eo.First(FirstSubExpression(0)).Second(SecondSubExpression(0)) ;
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/Section 16/featuremacros/featuremacros.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #ifdef __has_include
3 | # if __has_include()
4 | # include
5 | namespace fs = std::filesystem ;
6 | # else
7 | # include
8 | # namespace fs = std::experimental::filesystem ;
9 | # endif
10 | #endif
11 |
12 | int main() {
13 | fs::path p{"C:"} ;
14 |
15 | std::cout << __cpp_inline_variables << std::endl;
16 | std::cout << __cpp_capture_star_this << std::endl;
17 | }
--------------------------------------------------------------------------------
/Section 16/ifswitch/ifswitch.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | void Alloc() {
5 | int* p = (int *)malloc(sizeof(int));
6 | if (p != nullptr) {
7 | *p = 50;
8 | free(p);
9 | }
10 | //if (initialization condition) {
11 |
12 | if (int* p = (int*)malloc(sizeof(int)); p != nullptr) {
13 | *p = 50;
14 | free(p);
15 | }
16 | else {
17 | //Here p will be nullptr
18 | }
19 | }
20 | void Write(const std::string& data) {
21 |
22 | if (std::ofstream out{ "file.txt" }; out && !data.empty()) {
23 | std::cout << "Writing data into the file\n";
24 | out << data;
25 | }
26 | else {
27 | std::cout << "Not data to write\n" ;
28 | out << "####";
29 | }
30 |
31 | ///More statements
32 |
33 | }
34 |
35 | class FileInfo {
36 | public:
37 | enum Type{Executable, Text};
38 | Type GetFileType()const {
39 | return {} ;
40 | }
41 | size_t GetFileSize()const {
42 | return 0 ;
43 | }
44 | };
45 |
46 | FileInfo GetInfo(const std::string &file) {
47 | return {} ;
48 | }
49 |
50 | void Operate(const std::string &file) {
51 |
52 | switch (auto info = GetInfo(file) ;info.GetFileType()) {
53 | case FileInfo::Executable:
54 | break ;
55 | case FileInfo::Text:
56 | break ;
57 | default:
58 | break ;
59 | }
60 | //More statements
61 | }
62 |
63 | int main(){
64 | Write("") ;
65 | }
--------------------------------------------------------------------------------
/Section 16/inline variables/a.cpp:
--------------------------------------------------------------------------------
1 | #include "vars.h"
--------------------------------------------------------------------------------
/Section 16/inline variables/b.cpp:
--------------------------------------------------------------------------------
1 | #include "vars.h"
--------------------------------------------------------------------------------
/Section 16/inline variables/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "vars.h"
3 |
4 | int main() {
5 |
6 | }
--------------------------------------------------------------------------------
/Section 16/inline variables/vars.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | inline int global ;
3 | class Test {
4 | inline static int m_Data = 50 ;
5 | constexpr static int PATHSIZE= 255 ;
6 | int x = 5 ;
7 | };
--------------------------------------------------------------------------------
/Section 16/mandatorycopyelision/mandatorycopyelision.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #define DELETE_COPY_MOVE
3 | class Number {
4 | public:
5 | Number(int value) {
6 | std::cout << "Parameterized ctor\n" ;
7 | }
8 | #ifdef DELETE_COPY_MOVE
9 | Number(const Number &) = delete ;
10 | Number(Number &&) = delete ;
11 | #else
12 | Number(const Number &) {
13 | std::cout << "Copy ctor\n" ;
14 | }
15 | Number(Number &&){
16 | std::cout << "Move ctor\n" ;
17 | }
18 | #endif
19 | };
20 |
21 | void Foo(Number n) {
22 |
23 | }
24 |
25 | Number Create() {
26 | //Number n{0} ;
27 | //return n ;
28 |
29 | return Number{0} ;
30 | }
31 | template
32 | T Create(Args&&...args) {
33 | return T{args...} ;
34 | }
35 | int main() {
36 | //Number n1 = Number{3} ;
37 | //Foo(Number{3}) ;
38 |
39 | //auto n2 = Create() ;
40 |
41 | auto n3 = Create(0) ;
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/Section 16/nestednamespaces/nestednamespaces.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | namespace A{
3 | namespace B{
4 | namespace C{
5 | }
6 | }
7 | }
8 | namespace A::B::C{
9 | void Foo(){
10 | }
11 | }
12 |
13 | int main(){
14 | A::B::C::Foo() ;
15 | using A::B::C::Foo() ;
16 | using namespace A::B::C ;
17 | Foo() ;
18 | }
--------------------------------------------------------------------------------
/Section 16/noexcept/noexcept.cpp:
--------------------------------------------------------------------------------
1 | void Foo()noexcept{
2 | }
3 | void Bar(){
4 | }
5 |
6 | int main(){
7 | void (*p)() ;
8 | p = Foo ;
9 | p() ;
10 | }
--------------------------------------------------------------------------------
/Section 16/structuredbindings/structuredbindings.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include