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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:32:05+00:00 2026-05-15T13:32:05+00:00

I particularly like the simplicity of using STL containers in the straightforward way. I

  • 0

I particularly like the simplicity of using STL containers in the straightforward way.

I have never really figured out how to get the Boost library working on my dev platforms, in fact I don’t think I’ve even tried. I guess you could say I am just trying to delay the inevitable since Boost is clearly a helpful library that I should be using.

But my question is essentially the same as this topic: How to initialise a STL vector/list with a class without invoking the copy constructor

I have std::list<ExpensiveClass> mylist; and I just want a function that pushes a new instance into the list and calls the default constructor, rather than copying it from a temporary stack instance of it. In the other topic there was mention of move constructors. I looked them up and quite frankly it does nothing but strike fear into my heart. Two ampersands!!

Would it work if I just made an array of ExpensiveClass objects? ExpensiveClass *mylist = new ExpensiveClass[20]; Does this call the constructor 20 times?

Seems to me I should just use boost:ptr_list.

  • 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-05-15T13:32:05+00:00Added an answer on May 15, 2026 at 1:32 pm

    Inserting an object into a container invokes the copy constructor on that object. There’s really no way around that (yet), hence why pointer containers are used for large objects: it’s dirt cheap to copy a pointer.

    If you choose to use a container of smart pointers, you can either use one of the Boost pointer containers or you can use an STL container of shared_ptrs.

    To answer your question about:

    ExpensiveClass *mylist = new ExpensiveClass[20];
    

    The default constructor for ExpensiveClass is called 20 times: once for each element of the array.

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

Sidebar

Related Questions

I have a database table that stores imported information. For simplicity, its something like:
EDIT: Database names have been modified for simplicity I'm trying to get some dynamic
I am a reasonably competent programmer, with about 11 years experience. I particularly like
I'm using a particular database table like a Set data structure, i.e., you can
I have a text file which has a particular line something like sometext sometext
I have a particular web application that like most others, has to account for
I'd like to be able to comment on a particular Revision in SVN (using
I have a web-site based on PHP, to which I would like to add
I'm someone who does not particularly like Visual Studio at all and would much,
If one is designing an interface like ILookup (for simplicity, assume it's simply ICheckIfContained

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.