From 0bb69d80e6332fb36a43c37af4b454502ea466a8 Mon Sep 17 00:00:00 2001 From: Marzo Sette Torres Junior Date: Tue, 8 Aug 2017 16:37:19 +0200 Subject: [PATCH] Fixing memory handling in E.5 example Instead of constructing an array, it constructs and deletes a single double, and accesses elements as if it had constructed an array. --- CppCoreGuidelines.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 88f3650..f17402e 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -14704,8 +14704,8 @@ Not all member functions can be called. // if elem != nullptr then elem points to sz doubles public: Vector() : elem{nullptr}, sz{0}{} - Vector(int s) : elem{new double}, sz{s} { /* initialize elements */ } - ~Vector() { delete elem; } + Vector(int s) : elem{new double[s]}, sz{s} { /* initialize elements */ } + ~Vector() { delete [] elem; } double& operator[](int s) { return elem[s]; } // ... private: