diff --git a/Makefile b/Makefile index 8058fac..832c49d 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/headers/MyType.h b/headers/MyType.h new file mode 100644 index 0000000..d33ee14 --- /dev/null +++ b/headers/MyType.h @@ -0,0 +1,15 @@ +#ifndef MYTYPE_H +#define MYTYPE_H +#include +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 \ No newline at end of file diff --git a/src/MyType.cpp b/src/MyType.cpp new file mode 100644 index 0000000..2703aa5 --- /dev/null +++ b/src/MyType.cpp @@ -0,0 +1,11 @@ +#include "../headers/MyType.h" +#include + 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;} \ No newline at end of file diff --git a/src/sheet03.cpp b/src/sheet03.cpp new file mode 100644 index 0000000..af74888 --- /dev/null +++ b/src/sheet03.cpp @@ -0,0 +1,16 @@ +#include +#include +#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; +} \ No newline at end of file