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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:37:44+00:00 2026-05-25T14:37:44+00:00

Pretty much as per the title. The spec for std::vector<T>::resize seems to require that

  • 0

Pretty much as per the title.

The spec for std::vector<T>::resize seems to require that the src object be passed by value:

void resize(size_type n, T src = T() );

Why isn’t a reference to a constant object used here instead?

void resize(size_type n, T const& src = T() );

For instance, in this question, the pass-by-value aspect appears to cause stackoverflow issues, due to the creation of a temporary object on the stack.

If a reference to src was passed instead, we’d at least be able to workaround the issue by allocating a temporary on the heap which is passed-by-reference to ::resize().

It also seems that ::resize() is out of step with the other member functions for std::vector. For instance, the constructors take a src object by const& as expected:

vector (size_type n, T const& src = T(), Allocator const& = Allocator() );

EDIT: I dug out the c++03 standard and double checked that the function prototypes above are not mis-quoted…

  • 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-25T14:37:45+00:00Added an answer on May 25, 2026 at 2:37 pm

    It was a mistake in the Standard Library specification. It is fixed in C++11; std::vector now has two resize member functions declared as:

    void resize(size_type sz);
    void resize(size_type sz, const T& c);
    

    The difference between the two is that if the size of the container is larger after the resize, the first overload value initializes the new elements, while the second copy constructs them; this pattern is used for other member functions and in other containers too.

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

Sidebar

Related Questions

Pretty much every other editor that isn't a vi descendant (vim, cream, vi-emu) seems
Pretty much what the title says really. We have some code that is .NET
pretty much what the title says. I am using an Ajax Drop Down as
Title pretty much sums it up. The external style sheet has the following code:
The title pretty much explains my question. I would like to be able to
The title pretty much sums up the gist. I'm interested in whether it is
Ok, I'm developing an application that has been in pretty much continous development over
The title pretty much sums up my question. The deprecation and removal of case
Of the object-oriented languages I know, pretty much all but C++ and Objective-C compile
Pretty much as the question asks. Answers preferably in pseudo code and referenced. The

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.