From b69531ced41ccffb82a526e3d127ee0749e16148 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Thu, 12 Jul 2018 13:42:22 +0200 Subject: [PATCH] using shared_ptr --- src/core/sale.cpp | 11 ++++++++--- src/core/sale.h | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core/sale.cpp b/src/core/sale.cpp index 8407232..43ecabb 100644 --- a/src/core/sale.cpp +++ b/src/core/sale.cpp @@ -2,9 +2,14 @@ #include +void Sale::addArticle(std::shared_ptr
articlePtr) +{ + articles_.push_back(articlePtr); +} + int Sale::sumInCents() { - int test = std::accumulate(articles_.begin(), articles_.end(), 0, - [](int a, Article* b) { return a + b->getPrice(); }); - return test; + int sum = std::accumulate(articles_.begin(), articles_.end(), 0, + [](int a, std::shared_ptr
b) { return a + b->getPrice(); }); + return sum; } \ No newline at end of file diff --git a/src/core/sale.h b/src/core/sale.h index e4d016e..11253bd 100644 --- a/src/core/sale.h +++ b/src/core/sale.h @@ -13,9 +13,10 @@ class Sale : public Entity { public: int sumInCents(); + void addArticle(std::shared_ptr
articlePtr); private: boost::posix_time::ptime systemTime_{boost::posix_time::second_clock::local_time()}; - std::vector articles_{}; + std::vector> articles_{}; }; #endif \ No newline at end of file