Smart Pointers
You seem to be missing the point on smart pointers. The benefit of using unique_ptr
is that they help with memory management and clean up after themselves. The way you're using it:
std::unique_ptr<Node> tmp(std::make_unique<Node>(item, head));
head = tmp.release();
Is the same as doing this:
head = new Node(item, head);
When you call release
, the unique_ptr
stops looking after the memory, which is why you're having to explicitly call delete curr;
in your pop
method.
It may be worth you reviewing how this answer this answer uses unique_ptr
in their stack implementation.
Smart Pointers
You seem to be missing the point on smart pointers. The benefit of using unique_ptr
is that they help with memory management and clean up after themselves. The way you're using it:
std::unique_ptr<Node> tmp(std::make_unique<Node>(item, head));
head = tmp.release();
Is the same as doing this:
head = new Node(item, head);
When you call release
, the unique_ptr
stops looking after the memory, which is why you're having to explicitly call delete curr;
in your pop
method.
It may be worth you reviewing how this answer uses unique_ptr
in their stack implementation.
Smart Pointers
You seem to be missing the point on smart pointers. The benefit of using unique_ptr
is that they help with memory management and clean up after themselves. The way you're using it:
std::unique_ptr<Node> tmp(std::make_unique<Node>(item, head));
head = tmp.release();
Is the same as doing this:
head = new Node(item, head);
When you call release
, the unique_ptr
stops looking after the memory, which is why you're having to explicitly call delete curr;
in your pop
method.
It may be worth you reviewing how this answer uses unique_ptr
in their stack implementation.
Smart Pointers
You seem to be missing the point on smart pointers. The benefit of using unique_ptr
is that they help with memory management and clean up after themselves. The way you're using it:
std::unique_ptr<Node> tmp(std::make_unique<Node>(item, head));
head = tmp.release();
Is the same as doing this:
head = new Node(item, head);
When you call release
, the unique_ptr
stops looking after the memory, which is why you're having to explicitly call delete curr;
in your pop
method.
It may be worth you reviewing how this answer uses unique_ptr
in their stack implementation.
Smart Pointers
You seem to be missing the point on smart pointers. The benefit of using unique_ptr
is that they help with memory management and clean up after themselves. The way you're using it:
std::unique_ptr<Node> tmp(std::make_unique<Node>(item, head));
head = tmp.release();
Is the same as doing this:
head = new Node(item, head);
When you call release
, the unique_ptr
stops looking after the memory, which is why you're having to explicitly call delete curr;
in your pop
method.
Smart Pointers
You seem to be missing the point on smart pointers. The benefit of using unique_ptr
is that they help with memory management and clean up after themselves. The way you're using it:
std::unique_ptr<Node> tmp(std::make_unique<Node>(item, head));
head = tmp.release();
Is the same as doing this:
head = new Node(item, head);
When you call release
, the unique_ptr
stops looking after the memory, which is why you're having to explicitly call delete curr;
in your pop
method.
It may be worth you reviewing how this answer uses unique_ptr
in their stack implementation.
Smart Pointers
You seem to be missing the point on smart pointers. The benefit of using unique_ptr
is that they help with memory management and clean up after themselves. The way you're using it:
std::unique_ptr<Node> tmp(std::make_unique<Node>(item, head));
head = tmp.release();
Is the same as doing this:
head = new Node(item, head);
When you call release
, the unique_ptr
stops looking after the memory, which is why you're having to explicitly call delete curr;
in your pop
method.