fix memory leak in example of C.66 (#2096)

This commit is contained in:
Eisenwave 2023-06-25 05:40:24 +02:00 committed by GitHub
parent b11fbd0195
commit fe3e83e648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;