This commit is contained in:
Leon Wilzer 2022-11-08 15:41:38 +01:00
parent 0dc2b875d4
commit cc53df2dab
4 changed files with 47 additions and 0 deletions

View File

@ -16,6 +16,11 @@ sheet02:
chmod +x build/sheet02
build/sheet02
sheet03:
g++ src/sheet03.cpp -o ./build/sheet03
chmod +x build/sheet03
build/sheet03
pizza:
g++ src/pizza.cpp -o ./build/pizza
chmod +x build/pizza

15
headers/MyType.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef MYTYPE_H
#define MYTYPE_H
#include <string>
struct MyType{
std::string name;
unsigned age;
MyType(std::string n, unsigned a);
~MyType();
MyType(const MyType &t);
MyType& operator= (const MyType &t);
MyType(MyType &&t);
MyType& operator= (MyType &&t);
};
#endif

11
src/MyType.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "../headers/MyType.h"
#include <string>
std::string name;
unsigned age;
MyType(std::string n, unsigned a) : name(n), age(a) {std::cout << "ctor\n";}
~MyType() {}
MyType(const MyType &t) { std::cout << "copy ctor\n";}
MyType& operator= (const MyType &t) { std::cout << "copy ass ctor\n"; return *this;}
MyType(MyType &&t){std::cout << "move ctor\n";}
MyType& operator= (MyType &&t) { std::cout << "move ass ctor\n"; return t;}

16
src/sheet03.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <string>
#include <iostream>
#include "../headers/MyType.h"
int main()
{
MyType j("jj", 69);
MyType cj(j);
MyType caj("jj",420);
caj = j;
MyType mj(std::move(j));
MyType maj("jj", 69);
maj = std::move(cj);
return 0;
}