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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:01:26+00:00 2026-06-18T09:01:26+00:00

I face a problem similar to this one. int j = 6; int *k

  • 0

I face a problem similar to this one.

int j = 6;
int *k = new int[j]{4};

The warning is :

warning: non-constant array size in new, unable to verify length 
of initializer-list [enabled by default]

I face only a warning, no errors and I run with -std=gnu++11

Plus, I want the constructor called for every instance. If I print the array values, all

  • 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-18T09:01:27+00:00Added an answer on June 18, 2026 at 9:01 am

    The problem is exactly what the compiler is telling you.

    The dimension is known only at runtime, so you may only use runtime functionality, such as:

    std::vector<int> v(j, 4);
    // `v` contains `j` ints, all initialised to `4`
    

    If you have an element type that cannot be default-constructed, you may construct the elements in-place:

    std::vector<T> v;
    v.reserve(j);
    for (size_t i = 0; i < j; i++)
       v.emplace_back(ctor-args-here);
    

    You could probably also use an initializer list:

    std::vector<T> v{
       T(ctor-args-here), T(ctor-args-here), T(ctor-args-here),
       T(ctor-args-here), T(ctor-args-here), T(ctor-args-here)
    };
    

    and the objects will be moved or, at worst, copied.

    The point here is that vector elements don’t need to be default-constructible.

    (Unfortunately I’m not aware of a way to do this without the loop or code repetition.)

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

Sidebar

Related Questions

I am new to Derby and I noticed that I face similar problems as
My question is pretty similar to this one Hibernate Bi-Directional ManyToMany Updates with Second
I often face this problem.. Lets say ..In blog application, I need to email
Note that this isn't a problem I face, I'm more interested in what is
I often face the problem of wanting to add additional methods to classes I
I begin in Python language and face a problem with my script. On stackoverflow,
I face the following problem function book($memberid, $classid){ if (!book){ // update the db
Sometimes i face the following problem : string txt = con.Request.Params[Par_name].ToString();//the original par value
we have a classical 3-tier-architecture application. Now we face a little problem and we
My problem is certainly right on my face but I can't see it... I

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.