File tree 3 files changed +23
-5
lines changed
3 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ template <typename T> class AbstractList {
48
48
// / Create a final Value from the given Value
49
49
#define createFinalValue (value, finalValue, T ) \
50
50
finalValue = (T *)malloc(sizeof (T)); \
51
- memcpy (finalValue, &( value) , sizeof (T));
51
+ memcpy (finalValue, &value, sizeof (T));
52
52
53
53
/* *
54
54
* Class representing an abstract entry in the list.
@@ -65,6 +65,11 @@ template <typename T> class AbstractList {
65
65
*/
66
66
explicit AbstractEntry (T *value) : value(value) {}
67
67
68
+ /* !
69
+ * @brief Destructor of an AbstractEntry Object.
70
+ */
71
+ ~AbstractEntry () { value = nullptr ; }
72
+
68
73
/* !
69
74
* @brief Free the memory of the value to prevent memory leaks.
70
75
*/
Original file line number Diff line number Diff line change @@ -51,6 +51,14 @@ template <typename T> class DoubleLinkedList : public AbstractList<T> {
51
51
*/
52
52
explicit Entry (T *value) : AbstractList<T>::AbstractEntry(value) {}
53
53
54
+ /* !
55
+ * @brief Destructor of an Entry Object.
56
+ */
57
+ ~Entry () {
58
+ next = nullptr ;
59
+ prev = nullptr ;
60
+ }
61
+
54
62
/* !
55
63
* @brief Get the next entry of the list.
56
64
*
@@ -109,9 +117,9 @@ template <typename T> class DoubleLinkedList : public AbstractList<T> {
109
117
if (this ->isMutable ()) {
110
118
return (T *)current->getValue ();
111
119
} else {
112
- T val = * current->getValue ();
120
+ T * val = current->getValue ();
113
121
T *finalValue;
114
- createFinalValue (val, finalValue, T);
122
+ createFinalValue (* val, finalValue, T);
115
123
return finalValue;
116
124
}
117
125
}
Original file line number Diff line number Diff line change @@ -50,6 +50,11 @@ template <typename T> class SingleLinkedList : public AbstractList<T> {
50
50
*/
51
51
explicit Entry (T *value) : AbstractList<T>::AbstractEntry(value) {}
52
52
53
+ /* !
54
+ * @brief Destructor of an Entry Object.
55
+ */
56
+ ~Entry () { next = nullptr ; }
57
+
53
58
/* !
54
59
* @brief Get the next entry of the list.
55
60
*
@@ -87,9 +92,9 @@ template <typename T> class SingleLinkedList : public AbstractList<T> {
87
92
if (this ->isMutable ()) {
88
93
return (T *)current->getValue ();
89
94
} else {
90
- T val = * current->getValue ();
95
+ T * val = current->getValue ();
91
96
T *finalValue;
92
- createFinalValue (val, finalValue, T);
97
+ createFinalValue (* val, finalValue, T);
93
98
return finalValue;
94
99
}
95
100
}
You can’t perform that action at this time.
0 commit comments