From 8cf1283a4ffb9fe1901c29c087fa376de82726af Mon Sep 17 00:00:00 2001 From: angeld55 Date: Sat, 19 Feb 2022 23:30:52 +0200 Subject: clean up --- Sem. 11/example/Person.cpp | 99 ---------------------------------------------- Sem. 11/example/Person.h | 35 ---------------- Sem. 11/example/main.cpp | 17 -------- 3 files changed, 151 deletions(-) delete mode 100644 Sem. 11/example/Person.cpp delete mode 100644 Sem. 11/example/Person.h delete mode 100644 Sem. 11/example/main.cpp (limited to 'Sem. 11/example') diff --git a/Sem. 11/example/Person.cpp b/Sem. 11/example/Person.cpp deleted file mode 100644 index ae78280..0000000 --- a/Sem. 11/example/Person.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include "Person.h" -#include - -using namespace std; - -Person::Person() : Person("Unknown", 0) -{ - -} -Person::Person(const char* name, int age) : name(nullptr), age(age) -{ - cout << "Constr" << endl; - setName(name); - setAge(age); -} - -Person::Person(const Person& other) -{ - cout << "copy constr" << endl; - copyFrom(other); -} -Person::Person(Person&& other) -{ - cout << "Move constr" << endl; - - name = other.name; - age = other.age; - - other.name = nullptr; -} - -Person& Person::operator=(Person&& other) -{ - - std::cout << "Move op= " << endl; - if (this != &other) - { - free(); - - name = other.name; - other.name = nullptr; - - age = other.age; - - } - return *this; -} - -Person& Person::operator = (const Person& other) -{ - cout << "op =" << endl; - if (this != &other) - { - free(); - copyFrom(other); - } - return *this; -} -Person::~Person() -{ - cout << "Destructor" << endl; - free(); -} - -const char* Person::getName() const -{ - return name; -} - -int Person::getAge() const -{ - return age; -} - -void Person::setName(const char* name) -{ - delete[] this->name; - this->name = new char[strlen(name) + 1]; - strcpy(this->name, name); -} -void Person::setAge(int age) -{ - if (age < 0 || age > 120) - age = 40; - this->age = age; -} - -void Person::copyFrom(const Person& other) -{ - name = new char[strlen(other.name) + 1]; - strcpy(name, other.name); - - age = other.age; -} -void Person::free() -{ - delete[] name; - age = 0; -} \ No newline at end of file diff --git a/Sem. 11/example/Person.h b/Sem. 11/example/Person.h deleted file mode 100644 index 9a404c4..0000000 --- a/Sem. 11/example/Person.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -class Person -{ -public: - Person(); - Person(const char* name, int age); - - Person(const Person& other); - - Person(Person&& other); //move constr - - Person& operator=(Person&& other); // move op= - - Person& operator=(const Person& other); - ~Person(); - - void setName(const char* name); - void setAge(int age); - - const char* getName() const; - int getAge() const; - - void print(); - - -private: - - void copyFrom(const Person& other); - void free(); - - - char* name; - int age; -}; \ No newline at end of file diff --git a/Sem. 11/example/main.cpp b/Sem. 11/example/main.cpp deleted file mode 100644 index 80fef69..0000000 --- a/Sem. 11/example/main.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include "Person.h" -using namespace std; - -Person createPerson(const char* name, int age) -{ - Person p(name, age); - - return std::move(p); -} - -int main() -{ - Person p2("Petur",18); - p2 = createPerson("Ivan", 23); -} -- cgit v1.3.1-23-gd82d