add intro

This commit is contained in:
2025-02-05 16:48:25 +01:00
commit a0b1dd4c08
9 changed files with 850 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
#include "ClassA.h"
ClassA::ClassA() : _pNumber(new int(0))
{
}
ClassA::ClassA(const ClassA& other)
{
// shallow copy
//_pNumber = other._pNumber;
// deep copy
_pNumber = new int(*other._pNumber);
}
ClassA::~ClassA()
{
if (_pNumber != nullptr)
{
delete _pNumber;
_pNumber = nullptr;
}
}
+20
View File
@@ -0,0 +1,20 @@
#pragma once
class ClassA
{
// private
public:
// public
ClassA(); // default constructor
ClassA(const ClassA& other); // copy constructor
~ClassA(); // destructor
protected:
// protected
private:
// private
int* _pNumber = nullptr;
};
+38
View File
@@ -0,0 +1,38 @@
#include "functions.h"
#include <iostream>
using namespace std;
void functionF()
{
}
void printArray(int numbers[], size_t count)
{
for (size_t i = 0; i < count; i++)
{
cout << numbers[i] << " ";
}
cout << endl;
}
void changeInt(int n)
{
cout << "addr of n: " << &n << endl;
n *= 10;
}
void changeIntPointer(int* pN)
{
if (pN == nullptr) return;
cout << "addr of pN: " << &pN << endl;
cout << "pN: " << pN << endl;
*pN *= 10;
}
void changeIntReference(int& n)
{
cout << "addr of n: " << &n << endl;
n *= 10;
}
+13
View File
@@ -0,0 +1,13 @@
#pragma once
#ifndef __FUNCTIONS_H__
#define __FUNCTIONS_H__
//void functionE() {}
void functionF();
void printArray(int numbers[], size_t count);
void changeInt(int n);
void changeIntPointer(int* pN);
void changeIntReference(int& n);
#endif // !__FUNCTIONS_H__
+141
View File
@@ -0,0 +1,141 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{17fa2197-138c-4617-af1e-395e0b95b694}</ProjectGuid>
<RootNamespace>intro</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ClassA.cpp" />
<ClCompile Include="functions.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ClassA.h" />
<ClInclude Include="functions.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
+36
View File
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="functions.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ClassA.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="functions.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ClassA.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
+118
View File
@@ -0,0 +1,118 @@
#include <iostream>
#include <Windows.h>
#include <memory>
#include "functions.h"
#include "ClassA.h"
using namespace std;
void functionB() {}
void functionC();
void functionD(); // forward declaration
int main()
{
//std::cout << "Hello World!" << std::endl;
//cout << "Hallo" << endl;
////functionA(); // compiler error, function is not declared, but defined afterwards
//functionB(); // no error
////functionC(); // linker error, function is declared, but not defined
//functionD(); // no error
////functionE(); // linker error, function is defined in header and included in two different source files
//functionF(); // no error
//short s = 0;
//unsigned short us = 0;
//int i = 0;
//long l = 0;
//cout << "sizeof short: " << sizeof(s) << endl;
//cout << "sizeof int: " << sizeof(i) << endl;
//cout << "sizeof long: " << sizeof(l) << endl;
//cout << "sizeof long long: " << sizeof(long long) << endl;
//cout << "sizeof bool: " << sizeof(bool) << endl;
//BOOL b;
//int number;
//cin >> number;
//cout << "number: " << number << endl;
//char c;
//cin >> c;
//cout << "c: " << c << endl;
//string str;
//cin >> str;
//cout << "str: " << str << endl;
//char sz[128];
//cin >> sz;
//cout << "sz: " << sz << endl;
//cin >> sz;
//cout << "sz: " << sz << endl;
//int numbers[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
//cout << "print local array" << endl;
//for (size_t i = 0; i < sizeof(numbers) / sizeof(int); i++)
//{
// cout << numbers[i] << " ";
//}
//cout << endl;
//cout << "print remote array" << endl;
//printArray(numbers, size(numbers));
//int n = 1;
//changeInt(n);
//cout << "n (" << &n << "): " << n << endl;
//changeIntPointer(&n);
//cout << "n (" << &n << "): " << n << endl;
//changeIntReference(n);
//cout << "n (" << &n << "): " << n << endl;
//int* pNumber = nullptr;
//int* pNumber2 = new int;
//
//if (pNumber2 != nullptr)
//{
// delete pNumber2;
// pNumber2 = nullptr;
//}
//pNumber = new int;
//*pNumber += 10;
//pNumber = new int; // BAD - Memory Leak
//unique_ptr<int> un = make_unique<int>(0);
//*un = 100;
//
//shared_ptr<int> sn = make_shared<int>(0);
//*sn = 10;
//cout << "sn refs: " << sn.use_count() << endl;
//shared_ptr<int> sn2 = sn;
//cout << "sn refs: " << sn.use_count() << endl;
//sn.reset();
//cout << "sn refs: " << sn.use_count() << endl;
//cout << "sn2 refs: " << sn2.use_count() << endl;
//weak_ptr<int> wn = sn2;
//if (!wn.expired())
//{
// shared_ptr<int> ln = wn.lock();
// *ln = 1234;
// cout << "sn2 refs: " << sn2.use_count() << endl;
//}
//cout << "sn2 refs: " << sn2.use_count() << endl;
ClassA classA;
ClassA classA2 = classA;
return 0;
}
void functionA() {}
void functionD() {}