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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:55:30+00:00 2026-05-14T00:55:30+00:00

This looks simple but I am confused: The way I create a vector of

  • 0

This looks simple but I am confused: The way I create a vector of hundred, say, ints is

std::vector<int>  *pVect = new std::vector<int>(100);

However, looking at std::vector’s documentation I see that its constructor is of the form

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

So, how does the previous one work? Does new call the constructor with an initialization value obtained from the default constructor? If that is the case, would

std::vector<int, my_allocator> *pVect = new std::vector<int>(100, my_allocator);

where I pass my own allocator, also work?

  • 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-14T00:55:30+00:00Added an answer on May 14, 2026 at 12:55 am

    You are doing it all wrong. Just create it as an automatic object if all you need is a vector in the current scope and time

    std::vector<int> pVect(100);
    

    The constructor has default arguments for the second and third parameters. So it is callable with just an int. If you want to pass an own allocator, you have to pass a second argument since you can’t just skip it

    std::vector<int, myalloc> pVect(100, 0, myalloc(some_params));
    

    A dedicated example might clarify the matter

    void f(int age, int height = 180, int weight = 85);
    
    int main() { 
      f(25); // age = 25, height and weight taken from defaults.
      f(25, 90); // age=25, height = 90 (oops!). Won't pass a weight!
      f(25, 180, 90); // the desired call.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a simple stored procedure that looks like this (note: this
I'm very new in programming. The following task looks very simple but I don't
I've got a very simple WPF UserControl that looks like this: namespace MyUserControl {
I've got a very simple WPF UserControl that looks like this: namespace WpfControlLibrary1 {
I've got a simple java class that looks something like this: public class Skin
Has anyone used TUDBC ? This looks interesting, but I wonder how valuable it
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
Okay. I know this looks like the typical Why didn't he just Google it
I know at first glance (due to the title) this looks like one of
Update: looks like this is indeed a WiX limitation - Cannot add 64bit com+

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.