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 8606587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:07:49+00:00 2026-06-12T03:07:49+00:00

I wrote some flawed Huff compression code that I was trying to fix. The

  • 0

I wrote some flawed Huff compression code that I was trying to fix. The first thing I did was to switch the pointers to auto_ptr (There are reasons I didn’t use another smart pointer). I create a vector of auto_ptr but when I try to pass an auto_ptr to a function by *(vector.begin()) it doesn’t work.

My function code I’m trying to pass ownership to (it’s a member function as set_node):

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

and this is how I try to call it (p is a node):

p.set_node(w, '*', *nodes->begin(), *(nodes->begin()+1));

This is how the vector is declared:

vector<auto_ptr<Node> >* nodes = new vector<auto_ptr<Node> >;
  • 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-12T03:07:52+00:00Added an answer on June 12, 2026 at 3:07 am

    You cannot use std::auto_ptr in std::vector. You will need to find an alternative. The problem is that there is no copy in std::auto_ptr. The copy constructor is in some sense a move operation that steals the contents from the original auto pointer and moves it to the new one. That operation requires that the source is a non-const std::auto_ptr (as it removes the managed object from it).

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

Sidebar

Related Questions

I wrote some code in VHDL that is expected to look at a rotory
I wrote some code that activity starts a service to get some text from
I wrote some naive code(in the sense that it's synchronous calls) for a tableview
I wrote some ajax code that sends values to a php file for validation
I wrote some html/css/javascript code that was taken verbatim from a javascript textbook. For
I wrote some MooTools code that reads from YouTube's API in JSON and I
I wrote some PHP code that will allow me to create an html dropdown
I wrote some code that spits out an image. The code ran on my
I wrote some code to periodically post data to a NodeJs program that listens
i wrote some php code that can change any width=any number with the string

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.