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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:41:18+00:00 2026-06-14T06:41:18+00:00

I want to randomly assign to a boost::ptr_vector. Using the normal STL vector I

  • 0

I want to randomly assign to a boost::ptr_vector. Using the normal STL vector I would do this:

class A{

};

A* a1 = new A();
A* a2 = new A();

vector<A*> normal_vec;
normal_vec.resize(2);
normal_vec[1] = a1;
normal_vec[0] = a2;

I am trying to do the same with boost::ptr_vector:

A* a1 = new A();
A* a2 = new A();

ptr_vector<A> boost_vec;
boost_vec.resize(2);

boost_vec[1] = a1;
boost_vec[0] = a2;

But am getting the following error:

no match for ‘operator=’ in ‘v.boost::ptr_vector<A>::<anonymous>.boost::ptr_sequence_adapter<T, VoidPtrSeq, CloneAllocator>::operator[] [with T = A, VoidPtrSeq = std::vector<void*, std::allocator<void*> >, CloneAllocator = boost::heap_clone_allocator, boost::ptr_sequence_adapter<T, VoidPtrSeq, CloneAllocator>::reference = A&, boost::ptr_sequence_adapter<T, VoidPtrSeq, CloneAllocator>::size_type = long unsigned int](1ul) = a1’

But am struggling to make sense of this

  • 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-14T06:41:19+00:00Added an answer on June 14, 2026 at 6:41 am

    You should use ptr_vector<T>::replace instead of operator[]. The operator[] returns T& instead of T*&, so you can only assign value not a pointer.

    Also note that you have a memory leak when the second new for a2 throws, a1 is not deleted in the code below:

    A* a1 = new A();
    A* a2 = new A();
    

    Consider using std::unique_ptr.

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

Sidebar

Related Questions

Using Python I want to randomly rearrange sections of a string based on a
I want to assign weightings to a randomly generated number, with the weightings represented
We currently use this logic to center every new window: ASSIGN {&WINDOW-NAME}:X = (SESSION:WIDTH-PIXELS
I'm using DevExpree XtraTreeList Control, I want to randomly Set one of the first
I have a value, say 20010. I want to randomly divide this value over
I am using this method i created to randomly create different sprites to be
I have an ArrayList of strings, and I want to randomly change a string's
I'm creating a slider with 6 slides, and I want to randomly move between
I want to make an app that has a view that moves randomly or
I want to update 50% of the rows in a table, randomly selected. Is

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.