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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:38:19+00:00 2026-06-09T15:38:19+00:00

I am trying to use a ptr_vector to store some pointers, but I get

  • 0

I am trying to use a ptr_vector to store some pointers, but I get an error as soon as my main method.
Here is my code:

int main(void)
{
    boost::ptr_vector<string> temp;
    string s1 = "hi";
    string s2 = "hello";
    temp.push_back(&s1);
    temp.push_back(&s2);
    return 0;
}

This is the error message I am getting:

Critical error detected c0000374
Windows has triggered a breakpoint in Path_Tree.exe.

This may be due to a corruption of the heap, which indicates a bug in Path_Tree.exe or     any of the DLLs it has loaded.

This may also be due to the user pressing F12 while Path_Tree.exe has focus.

The output window may have more diagnostic information.
The program '[7344] Path_Tree.exe: Native' has exited with code 0 (0x0).

What am I doing wrong?
Thanks!

  • 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-09T15:38:20+00:00Added an answer on June 9, 2026 at 3:38 pm

    ptr_vector takes ownership of the objects pointed to by the pointers you give to it (meaning that it calls delete on those pointers when it is done with them). If you want just a vector of pointers, use:

    int main()
    {
        std::vector<string*> temp;
        //s1 and s2 manage their own lifetimes
        //(and will be destructed at the end of the scope)
        string s1 = "hi";
        string s2 = "hello";
        //temp[0] and temp[1] point to s1 and s2 respectively
        temp.push_back(&s1);
        temp.push_back(&s2);
        return 0;
    }
    

    otherwise, you should allocate your strings using new, and then push_back the resulting pointers:

    int main()
    {
        boost::ptr_vector<string> temp;
        temp.push_back(new string("hi"));
        temp.push_back(new string("hello"));
        return 0;
    }
    

    If you want just a container of strings, the usual thing would be a vector of strings:

    int main()
    {
        std::vector<string> temp;
        //s1 and s2 manage their own lifetimes
        //(and will be destructed at the end of the scope)
        string s1 = "hi";
        string s2 = "hello";
        //temp[0] and temp[1] refer to copies of s1 and s2.
        //The vector manages the lifetimes of these copies,
        //and will destroy them when it goes out of scope.
        temp.push_back(s1);
        temp.push_back(s2);
        return 0;
    }
    

    ptr_vector is meant to make it easier to have polymorphic objects with value semantics. If your strings are not polymorphic in the first place then ptr_vector is totally unnecessary.

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

Sidebar

Related Questions

I'm trying to use shared_ptr for the first time here, but I'm having some
I'm trying to rewrite some code to make use of SSE. However, for some
I'm quite new to smart pointers and was trying to refactor some existing code
I am trying to use shared_ptr with my class but for some reason I
I'm trying to use some code that I wrote on another computer that splits
I'm trying to re-program instruction vector table. Here is the code I use: #include
I am trying to use the auto_ptr in my code, but apparently something goes
Was trying to find the best way to use ptr_vector to store, access and
I get the following error when trying to use: typedef QSharedPointer<Test> CTest CTest* Module::function(params)
I'm trying to use Boost::Interprocess but I have some compiler errors when trying to

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.