Files
hwr2023_a/CPlusPlus/intro/main.cpp
T
2025-02-05 13:00:51 +01:00

126 lines
2.8 KiB
C++

#include <iostream>
#include <Windows.h>
#include <memory>
#include "functions.h"
#include "ClassA.h"
int number = 0;
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 not defined
//functionB(); // no error
////functionC(); // linker error - function declared, but not defined
//functionD(); // no error
////functionE(); // linker error - function is defined twice, because of two includes in two source files
//functionF(); // no error
//short s = 0;
//unsigned short us = 0;
//int i = 0;
//long l = 0;
//cout << "size of short: " << sizeof(s) << endl;
//cout << "size of int: " << sizeof(i) << endl;
//cout << "size of long: " << sizeof(l) << endl;
//cout << "size of long long: " << sizeof(long long) << endl;
//cout << "size of bool: " << sizeof(bool) << endl;
//BYTE b;
//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[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
//int* pNumber = new int(0);
//cout << "local array print" << endl;
//for (size_t i = 0; i < sizeof(numbers) / sizeof(int); i++)
//{
// std::cout << numbers[i] << " ";
//}
//std::cout << std::endl;
//cout << "function array print" << endl;
//printArray(numbers, size(numbers));
//int n = 1;
//changeInt(n);
//cout << "n (" << &n << "): " << n << endl;
//changeIntPointer(&n);
//cout << "n (" << &n << "): " << n << endl;
//int* pN = nullptr;
//int* pN2 = new int;
//*pN2 = 1234;
//delete pN2;
//pN2 = nullptr;
//if (pN2 != nullptr)
//{
// *pN2 = 1234;
//}
//pN = new int;
//*pN += 10;
//pN = new int; // BAD - Memory Leak
//changeIntReference(n);
//cout << "n (" << &n << "): " << n << endl;
//unique_ptr<int> un = make_unique<int>(0);
//*un = 10;
////unique_ptr<int> un2 = un; // not possible, because it is unique
//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;
//cout << "sn2 refs: " << sn2.use_count() << endl;
//if (!wn.expired())
//{
// shared_ptr<int> ln = wn.lock();
// *ln *= 23;
// 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() {}