Skip to content

Commit

Permalink
Add copy constructor for the List class template.
Browse files Browse the repository at this point in the history
  • Loading branch information
BartVandewoestyne committed Feb 15, 2024
1 parent cf5509e commit 2915aaf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Foundation_Classes/List.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ List<Item>::List(long size) : _size(size), _count(0) {
_items = new Item[size];
}

// TODO: Copy constructor.
// Overrides the default copy constructor so that member data are initialized properly.
template<class Item>
List<Item>::List(List& other) {
_size = other._size;
_count = other._count;

_items = new Item[_size];

for (long i = 0; i < _count; ++i) {
_items[i] = other._items[i];
}
}

template<class Item>
List<Item>::~List() {
Expand Down

0 comments on commit 2915aaf

Please sign in to comment.