using shared_ptr

This commit is contained in:
Martin Brodbeck 2018-07-12 13:42:22 +02:00
parent 2c5368c621
commit b69531ced4
2 changed files with 10 additions and 4 deletions

View File

@ -2,9 +2,14 @@
#include <numeric> #include <numeric>
void Sale::addArticle(std::shared_ptr<Article> articlePtr)
{
articles_.push_back(articlePtr);
}
int Sale::sumInCents() int Sale::sumInCents()
{ {
int test = std::accumulate(articles_.begin(), articles_.end(), 0, int sum = std::accumulate(articles_.begin(), articles_.end(), 0,
[](int a, Article* b) { return a + b->getPrice(); }); [](int a, std::shared_ptr<Article> b) { return a + b->getPrice(); });
return test; return sum;
} }

View File

@ -13,9 +13,10 @@ class Sale : public Entity
{ {
public: public:
int sumInCents(); int sumInCents();
void addArticle(std::shared_ptr<Article> articlePtr);
private: private:
boost::posix_time::ptime systemTime_{boost::posix_time::second_clock::local_time()}; boost::posix_time::ptime systemTime_{boost::posix_time::second_clock::local_time()};
std::vector<Article*> articles_{}; std::vector<std::shared_ptr<Article>> articles_{};
}; };
#endif #endif