diff options
| author | Connor McDowell <[email protected]> | 2024-03-09 17:40:06 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-03-09 17:40:06 -0800 |
| commit | 01dc1dbc161fadbe169908c0200d3d2a39490a72 (patch) | |
| tree | 22c4b54562207aaa0626dce79f820ed6a2600507 /My structures/ContactList.hpp | |
| parent | test classes created (diff) | |
| download | homework-8-connormcdowell275-main.tar.xz homework-8-connormcdowell275-main.zip | |
Diffstat (limited to 'My structures/ContactList.hpp')
| -rw-r--r-- | My structures/ContactList.hpp | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/My structures/ContactList.hpp b/My structures/ContactList.hpp index 5287baa..2f55ac7 100644 --- a/My structures/ContactList.hpp +++ b/My structures/ContactList.hpp @@ -2,6 +2,12 @@ #define CONTACT_LIST_HPP #include <algorithm> +#include "Contact.hpp" +#include <iostream> + +using std::cin; +using std::cout; +using std::endl; // NOTE: ALL USES OF TERM LIST REFER TO A SHORTHAND FORM OF ContactList, NOT AN ACTUAL LIST. // ContactList's DATA SAVING IS IN AN ARRAY FORMAT @@ -12,13 +18,14 @@ namespace myStructures class ContactList { public: - ContactList() = default; ContactList(size_t length); //Creates contact list of this size + ContactList() = default; + ContactList(const CList* contacts, const size_t& length); //Makes a copy of another contact list ~ContactList(); ContactList(const ContactList& copy); //deep copy constructor - ContactList& operator=(const ContactList& rhs); //deep copy assignment + ContactList& operator=(ContactList& rhs); //deep copy assignment ContactList(ContactList&& move) noexcept; //reference(move) constructor ContactList& operator=(ContactList&& rhs) noexcept; //reference(move) assignment @@ -41,19 +48,20 @@ namespace myStructures CList First() const; // returns first contact copy CList& operator[](const int& index); // returns contact reference via [] overload - CList operator[](const int& index) const; // returns contact copy via [] overload + CList operator[](int& index); // returns contact copy via [] overload explicit operator bool() const; // overloads ContactList to return true/false as boolean // operator bool operator==(const ContactList<CList>& rhs) const; //if(newContactList == oldContactList) bool Empty() const; // is the list empty? - + + CList* AllocateContactList(const size_t& length); + private: CList* contacts_{ nullptr }; - size_t length_{ 0 }; // entire length of array - size_t size_{ 0 }; // number of actual elements - - CList* AllocateContactList(const size_t& length); + size_t length_{ 10 }; // entire length of array + size_t size_{ 1 }; // number of actual elements + }; @@ -94,7 +102,7 @@ namespace myStructures } template <class CList> - ContactList<CList>& ContactList<CList>::operator=(const ContactList& rhs) + ContactList<CList>& ContactList<CList>::operator=( ContactList& rhs) { if (this != &rhs) { @@ -138,7 +146,10 @@ namespace myStructures template <class CList> void ContactList<CList>::Print() const { - + for(auto i = 0u; i < length_; i++) + { + contacts_[i].print(); + } } template <class CList> @@ -154,8 +165,12 @@ namespace myStructures // what ifs // what if: end of the array is the beginning (empty) + if (size_ == 0) + { + index = 0; + } // what if: in the body of the array - if(size_ < length_) + if(size_ > 0 && size_ < length_) { index = size_; } @@ -166,8 +181,10 @@ namespace myStructures if(size_ >= length_) { //increase size of array - this = ContactList(contacts_, length_ * 2); + //*this = ContactList(contacts_, length_ * 2); + ContactList newContacts(contacts_, length_ * 2); + *this = newContacts; } @@ -248,13 +265,13 @@ namespace myStructures template <class CList> CList& ContactList<CList>::operator[](const int& index) { - + return contacts_[index]; } template <class CList> - CList ContactList<CList>::operator[](const int& index) const + CList ContactList<CList>::operator[](int& index) { - + return *this; } template <class CList> |