mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
fix memory leak in example of C.66 (#2096)
This commit is contained in:
parent
b11fbd0195
commit
fe3e83e648
|
@ -6436,8 +6436,13 @@ A non-throwing move will be used more efficiently by standard-library and langua
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class Vector {
|
class Vector {
|
||||||
public:
|
public:
|
||||||
Vector(Vector&& a) noexcept :elem{a.elem}, sz{a.sz} { a.sz = 0; a.elem = nullptr; }
|
Vector(Vector&& a) noexcept :elem{a.elem}, sz{a.sz} { a.elem = nullptr; a.sz = 0; }
|
||||||
Vector& operator=(Vector&& a) noexcept { elem = a.elem; sz = a.sz; a.sz = 0; a.elem = nullptr; }
|
Vector& operator=(Vector&& a) noexcept {
|
||||||
|
delete elem;
|
||||||
|
elem = a.elem; a.elem = nullptr;
|
||||||
|
sz = a.sz; a.sz = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
// ...
|
// ...
|
||||||
private:
|
private:
|
||||||
T* elem;
|
T* elem;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user