From bf76daffa42e8cd4bb9903daca5f7a9dee8d9508 Mon Sep 17 00:00:00 2001 From: Pieter van Ginkel Date: Sat, 19 Nov 2022 10:47:49 +0100 Subject: [PATCH] Disable copying. Deleted the copy constructor and the copy operator because it's not supported. The default copy constructor and operator give you a copy, but when one of them is deleted, that also deletes the memory the other instance is pointing to. --- LinkedList.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/LinkedList.h b/LinkedList.h index 742933a..99e95ae 100644 --- a/LinkedList.h +++ b/LinkedList.h @@ -44,6 +44,7 @@ class LinkedList{ public: LinkedList(); LinkedList(int sizeIndex, T _t); //initiate list size and default value + LinkedList(const LinkedList&) = delete; // copy constructor isn't supported virtual ~LinkedList(); /* @@ -104,8 +105,8 @@ class LinkedList{ // add support to array brakets [] operator inline T& operator[](int index); inline T& operator[](size_t& i) { return this->get(i); } - inline const T& operator[](const size_t& i) const { return this->get(i); } - + inline const T& operator[](const size_t& i) const { return this->get(i); } + LinkedList& operator=(const LinkedList& other) = delete; // copy operator isn't supported }; // Initialize LinkedList with false values