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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:27:44+00:00 2026-06-02T19:27:44+00:00

I am attempting to use a boost::ptr_vector in a current project, and was wondering

  • 0

I am attempting to use a boost::ptr_vector in a current project, and was wondering if it was possible to use a parameterized constructor in the push_back() method, or if I am required to use a default constructor?

As a secondary question will it still use a default constructor if I define it?


This might not be the best follow-up, but most of the implementations that I have seen with the boost::ptr_vector show that the push_back() method takes the new operator. Is it possible to create an object, and then give the pointer to that object to the push_back() method of the container?

  • 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-02T19:27:45+00:00Added an answer on June 2, 2026 at 7:27 pm

    For the purpose of using a ptr_vector or any ptr_container much like a standard vector, or container. it is legal to use any constructor that is desired as long as the constructor is defined (defaults will also work). The only real difference is that a ptr_container takes a pointer instead of a static object, and supports cloning which acts as a deep copy as apposed to shallow copies.

    On the follow-up. it is possible to use an existing object into the push_back() method it is:

    #include <boost/ptr_container/ptr_vector.hpp>
    #include <vector>
    typedef boost::ptr_vector<Base> thing;
    void foo(void){
        thing Bar;
        Object * newObj = new Object(param1, param2);
        bar.push_back(newObj);
    }
    

    it would seem that it attempts to use the information stored in the pointer of the object to place in the array. in that case it would be possible to give a static object. though this gives me a strange feeling when I consider giving a static object for some reason (something along the lines of a pointer container should only really be used for unique items/pointers.)

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

Sidebar

Related Questions

I'm attempting to use the boost library in my C++ project (Visual Studio 2008).
In attempting to use std::select1st from <functional> in a VS2008 project I found that
Im attempting to use websockets for a project. It needs to use the ipad,
I am attempting to use boost::asio to read and write from a device on
I'm attempting to use boost::format, where my formatting string is the HTML below. I
Im attempting to use fxCop on a C# Project as kind of basis for
In attempting to use scipy's quad method to integrate a gaussian (lets say there's
I'm attempting to use boost::date_time to parse a date string (obtained from the Twitter
I am attempting to use a findcontrol method to dynamically fill a drop down
Attempting to use the data series from this example no longer passes the JSONLint

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.