Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

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.

added 158 characters in body
Source Link
forsvarir
  • 11.8k
  • 7
  • 39
  • 72

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.

Source Link
forsvarir
  • 11.8k
  • 7
  • 39
  • 72

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.

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /