Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8391971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:23:50+00:00 2026-06-09T19:23:50+00:00

Is there a way to set an auto_ptr to NULL, or the equivalent? For

  • 0

Is there a way to set an auto_ptr to NULL, or the equivalent? For instance, I’m creating a binary tree composed of node objects:

struct Node {
    int weight;
    char litteral;
    auto_ptr<Node> childL;
    auto_ptr<Node> childR;
    void set_node(int w, char l, auto_ptr<Node> L, auto_ptr<Node> R){
        weight = w;
        litteral = l;
        childL = L;
        childR = R;
    }
};

For an node that is not the parent node, I had planned on doing this:

auto_ptr<Node> n(new Node);
(*n).set_node(i->second, i->first, NULL, NULL);

This throws an error. Is there any way to set it to NULL, or is there another course of action that would make sense?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:23:52+00:00Added an answer on June 9, 2026 at 7:23 pm

    The std::auto_ptr constructor that takes a pointer is explicit, to help prevent accidentally transferring ownership to an std::auto_ptr. You can pass in two default-constructed std::auto_ptr objects:

    (*n).set_node(i->second, i->first, std::auto_ptr<Node>(), std::auto_ptr<Node>());
    

    If the Standard Library implementations you are targeting include std::unique_ptr, consider using that instead. It does not have the problematic copy semantics of std::auto_ptr, so std::auto_ptr has been deprecated and replaced by std::unique_ptr.

    std::unique_ptr also has a converting constructor that allows implicit conversion from a null pointer constant, so your code passing NULL would work just fine if you were using std::unique_ptr.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to set breakpoint on setter/getter in auto-implemented property? int Counter
Is there way to set @include mixin(); to variable? I tried this @mixin bg-gradient($fallback,
Is there any way to set up a PendingIntent with the download manager? Or
Is there any way to set order by clause in HQL by run time.
Is there any way to set DPI (dots per inch) in case of PDFsharp?
Is there a way to set a constant width for geom_bar() in the event
Is there a way to set up an appengine web application to deploy on
Is there a way to set app icon only based by name. For example
Is there a way to set the PRIMARY KEY in a single CREATE TABLE
Is there a way to set the file creation date of all committed files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.