mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
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.
This commit is contained in:
parent
e61f111301
commit
0bb69d80e6
|
@ -14704,8 +14704,8 @@ Not all member functions can be called.
|
||||||
// if elem != nullptr then elem points to sz doubles
|
// if elem != nullptr then elem points to sz doubles
|
||||||
public:
|
public:
|
||||||
Vector() : elem{nullptr}, sz{0}{}
|
Vector() : elem{nullptr}, sz{0}{}
|
||||||
Vector(int s) : elem{new double}, sz{s} { /* initialize elements */ }
|
Vector(int s) : elem{new double[s]}, sz{s} { /* initialize elements */ }
|
||||||
~Vector() { delete elem; }
|
~Vector() { delete [] elem; }
|
||||||
double& operator[](int s) { return elem[s]; }
|
double& operator[](int s) { return elem[s]; }
|
||||||
// ...
|
// ...
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user