diff --git a/src/core/entityint.cpp b/src/core/entityint.cpp index ba8c356..835c5ff 100644 --- a/src/core/entityint.cpp +++ b/src/core/entityint.cpp @@ -1,5 +1,9 @@ #include "entityint.h" +EntityInt::EntityInt(int id) { + id_ = id; +} + void EntityInt::setId(int id) { id_ = id; } diff --git a/src/core/entityint.h b/src/core/entityint.h index 1a1cf59..9430a70 100644 --- a/src/core/entityint.h +++ b/src/core/entityint.h @@ -5,11 +5,13 @@ class EntityInt : public Entity { -public: + public: + EntityInt() = default; + EntityInt(int id); void setId(int id); - int getId() const {return id_;}; - -protected: + int getId() const { return id_; }; + + protected: int id_{}; }; diff --git a/src/core/seller.cpp b/src/core/seller.cpp index bcb470d..cc053ce 100644 --- a/src/core/seller.cpp +++ b/src/core/seller.cpp @@ -7,15 +7,14 @@ Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo, int numArticlesOffered) - : EntityInt() + : EntityInt(sellerNo) { firstName_ = firstName; lastName_ = lastName; - sellerNo_ = sellerNo; numArticlesOffered_ = numArticlesOffered; } -void Seller::setSellerNo(int seller_no) { sellerNo_ = seller_no; id_ = seller_no;} +void Seller::setSellerNo(int seller_no) { setId(seller_no); } void Seller::setFirstName(const std::string& firstName) { firstName_ = firstName; } @@ -33,13 +32,13 @@ std::string Seller::getFirstName() const { return firstName_; } std::string Seller::getLastName() const { return lastName_; } -int Seller::getSellerNo() const { return sellerNo_; } +int Seller::getSellerNo() const { return getId(); } std::string Seller::getSellerNoAsString() const { std::stringstream selNoStr; - selNoStr << std::setfill('0') << std::setw(3) << sellerNo_; + selNoStr << std::setfill('0') << std::setw(3) << id_; return selNoStr.str(); ; @@ -104,8 +103,8 @@ int Seller::sumInCents() std::string Seller::sumAsString() { return formatCentAsEuroString(sumInCents()); } -bool operator<(const Seller& li, const Seller& re) { return li.sellerNo_ < re.sellerNo_; } +bool operator<(const Seller& li, const Seller& re) { return li.id_ < re.id_; } bool operator<(const std::unique_ptr& li, const std::unique_ptr& re) { - return li->sellerNo_ < re->sellerNo_; + return li->id_ < re->id_; } diff --git a/src/core/seller.h b/src/core/seller.h index bcfa50f..a4bfde1 100644 --- a/src/core/seller.h +++ b/src/core/seller.h @@ -14,7 +14,7 @@ class Seller : public EntityInt { public: Seller() = default; - // virtual ~Seller() = default; + ~Seller() = default; Seller(const std::string& firstName, const std::string& lastName, int sellerNo = 0, int numArticlesOffered = 0); @@ -42,7 +42,6 @@ class Seller : public EntityInt friend bool operator<(const std::unique_ptr& li, const std::unique_ptr& re); private: - int sellerNo_{-1}; int numArticlesOffered_{}; std::string firstName_{}; std::string lastName_{};