From 568a5bc98eefaf71d05228cb8c7e9ce1637886c9 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Mon, 31 Dec 2018 13:45:55 +0100 Subject: [PATCH] =?UTF-8?q?10=5FPITF:=20weitere=20=C3=84nderungen,=20immer?= =?UTF-8?q?noch=20die=20selbe=20Fehlermeldung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/10_PITF/Testat/Bank.cpp | 9 +++++++-- src/10_PITF/Testat/Bank.h | 3 ++- src/10_PITF/Testat/BankAccount.cpp | 8 +++----- src/10_PITF/Testat/BankAccount.h | 2 +- src/10_PITF/Testat/Person.cpp | 6 +++++- src/10_PITF/Testat/Person.h | 3 ++- src/10_PITF/Testat/main.cpp | 14 +++++++------- 7 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/10_PITF/Testat/Bank.cpp b/src/10_PITF/Testat/Bank.cpp index 4c7bc94..1bf3eb6 100644 --- a/src/10_PITF/Testat/Bank.cpp +++ b/src/10_PITF/Testat/Bank.cpp @@ -3,12 +3,17 @@ #include "Bank.h" -Bank::Bank(std::string name) : name(std::move(name)) { +Bank::Bank(std::string const& name) : name(name) { } +Bank::Bank(Bank* bank) : name(bank->name) { + money.swap(bank->money); + accounts.swap(bank->accounts); +} + void Bank::addAccount(std::unique_ptr account) { - accounts.insert(std::move(account)); + this->accounts.insert(std::move(account)); } void Bank::addMoney(std::unique_ptr money) { diff --git a/src/10_PITF/Testat/Bank.h b/src/10_PITF/Testat/Bank.h index bc09d23..b38b9a9 100644 --- a/src/10_PITF/Testat/Bank.h +++ b/src/10_PITF/Testat/Bank.h @@ -10,7 +10,8 @@ private: std::set> accounts; std::set> money; public: - explicit Bank(std::string name); + explicit Bank(std::string const& name); + explicit Bank(Bank* bank); void addAccount(std::unique_ptr account); void addMoney(std::unique_ptr money); std::set> getAccounts(); diff --git a/src/10_PITF/Testat/BankAccount.cpp b/src/10_PITF/Testat/BankAccount.cpp index 48e067d..7f05675 100644 --- a/src/10_PITF/Testat/BankAccount.cpp +++ b/src/10_PITF/Testat/BankAccount.cpp @@ -5,18 +5,16 @@ #include "BankAccount.h" #include "CashFactory.h" -BankAccount::BankAccount(std::shared_ptr owner, std::string name) : name(std::move(name)), owner(std::move(owner)) { +BankAccount::BankAccount(std::shared_ptr const& owner, std::string const& name) : name(name), owner(std::move(owner)) { } -BankAccount::BankAccount(BankAccount *bankAccount) { - this->name = bankAccount->name; +BankAccount::BankAccount(BankAccount *bankAccount) : name(bankAccount->name) { money.swap(bankAccount->money); owner.swap(bankAccount->owner); } -BankAccount::BankAccount(BankAccount &bankAccount) { - this->name = bankAccount.name; +BankAccount::BankAccount(BankAccount &bankAccount) : name(bankAccount.name) { money.swap(bankAccount.money); owner.swap(bankAccount.owner); } diff --git a/src/10_PITF/Testat/BankAccount.h b/src/10_PITF/Testat/BankAccount.h index a786f0d..98d9f00 100644 --- a/src/10_PITF/Testat/BankAccount.h +++ b/src/10_PITF/Testat/BankAccount.h @@ -13,7 +13,7 @@ private: std::shared_ptr owner; std::unique_ptr money; public: - explicit BankAccount(std::shared_ptr owner, std::string name); + explicit BankAccount(std::shared_ptr const& owner, std::string const& name); explicit BankAccount(BankAccount *bankAccount); BankAccount(BankAccount& bankAccount); std::unique_ptr operator+(Money* money); diff --git a/src/10_PITF/Testat/Person.cpp b/src/10_PITF/Testat/Person.cpp index c33c5e1..6bc3054 100644 --- a/src/10_PITF/Testat/Person.cpp +++ b/src/10_PITF/Testat/Person.cpp @@ -2,10 +2,14 @@ #include "Person.h" -Person::Person(std::string name) : name(std::move(name)){ +Person::Person(std::string const& name) : name(name) { } +Person::Person(Person *person) : name(person->name) { + money.swap(person->money); +} + std::string Person::getName() { return name; } \ No newline at end of file diff --git a/src/10_PITF/Testat/Person.h b/src/10_PITF/Testat/Person.h index f272851..ed7ca41 100644 --- a/src/10_PITF/Testat/Person.h +++ b/src/10_PITF/Testat/Person.h @@ -12,7 +12,8 @@ private: std::string name; std::vector> money; public: - explicit Person(std::string name); + explicit Person(std::string const& name); + explicit Person(Person* person); std::string getName(); }; diff --git a/src/10_PITF/Testat/main.cpp b/src/10_PITF/Testat/main.cpp index bed1c58..4993724 100644 --- a/src/10_PITF/Testat/main.cpp +++ b/src/10_PITF/Testat/main.cpp @@ -39,7 +39,7 @@ std::ostream &operator<<(std::ostream &os, std::unique_ptr money) { return os; } -std::ostream &operator<<(std::ostream &os, std::shared_ptr person) { +std::ostream &operator<<(std::ostream &os, std::shared_ptr const& person) { os << person->getName(); return os; } @@ -55,13 +55,13 @@ CashFactory *cashFactory; void setup() { - std::unique_ptr bank1 = std::make_unique(Bank("Bank 1")); - std::unique_ptr bank2 = std::make_unique(Bank("Bank 2")); - std::unique_ptr bank3 = std::make_unique(Bank("Bank 3")); + std::unique_ptr bank1 = std::make_unique(new Bank("Bank 1")); + std::unique_ptr bank2 = std::make_unique(new Bank("Bank 2")); + std::unique_ptr bank3 = std::make_unique(new Bank("Bank 3")); - std::shared_ptr max = std::make_shared(Person("Max Müller")); - std::shared_ptr marius = std::make_shared(Person("Marius Müller")); - std::shared_ptr alex = std::make_shared(Person("Alex Maier")); + std::shared_ptr max = std::make_shared(new Person("Max Müller")); + std::shared_ptr marius = std::make_shared(new Person("Marius Müller")); + std::shared_ptr alex = std::make_shared(new Person("Alex Maier")); owners.insert(max); owners.insert(marius);