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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:28:01+00:00 2026-05-23T12:28:01+00:00

When I ran static code analyzer QACPP, I got a warning. According to the

  • 0

When I ran static code analyzer QACPP, I got a warning. According to the QACPP documentation, initializing with {0} only works for built in types. To initialize an array of objects of type A, {} must be used. As below:

int i[5] = {0};  // Only works with built-in types.
A   a[5] = {};   // OK, works with both built-in and class types

Is this a standard C++ rule? According to this, an array of pointers to a class type must also be initialized with {}, right?

Does this statement:

A* ap[5] = {}

initialise the 5 pointers with NULL?

QACPP throws me a warning when I used A* ap[5] = {NULL}, though the code compiles and works perfectly even otherwise.


Additional

I think the warning was more because the array is static.

And here is the explanation I found in the documentation:

There are many problems with the use
of objects with static storage
duration, particularly those declared
outside of functions. If many
functions can access a static object
this situation may become difficult to
maintain. Also, in the case of
multi-threaded applications it becomes
necessary to protect with mutex each
static object that can be accessed
concurrently. It is therefore a good
idea to limit the scope of a static
object as much as possible, so that
you know where such object is
accessed.

Namespace or class objects with static
storage duration will be initialised
at the start of the program, before
calling main(), and the order of
initialisation is unspecified.
Reliance on the order of
initialisation may lead to objects
being used before they are
initialised. If an exception is thrown
as a result of initialising a
non-local object the program will
immediately terminate.

Block scope objects with static
storage duration will be initialised
when the function is first called.
Therefore, it is best to use the
singleton pattern instead of namespace
objects and static data members. This
entails wrapping the object in a
function as a local static object, and
having the function return a reference
to this object.

  • 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-23T12:28:01+00:00Added an answer on May 23, 2026 at 12:28 pm

    Yes, it is a standard rule. An array is an aggregate. The rules of initialization are explicitly mentioned in the standard for aggregates.

    Does this statement: A* ap[5] = {}
    intialise the 5 pointers with NULL?

    Yes

    QACPP throws me a warning when I used A* ap[5] = {NULL}

    What warning? Maybe the warning is that you initialized only the first element, and the others will stay NULL. Of course, it may be what you need. But then, the compiler is just warning you 🙂

    I think this question and answer will be very interesting. What are Aggregates and PODs and how/why are they special?

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

Sidebar

Related Questions

This one is sort of esoteric. I ran into a NullReferenceException while trying to
Newbie Scala Question: Say I want to do this [Java code] in Scala: public
I was working on an abstract class to save on some code for a
I’m having some difficulties while trying to consume an unmanaged-code dll from my application
Just ran into this: #include <iostream> using namespace std; int main(int argc, char** argv)
I ran into a problem this week regarding implicit conversions in C# on collections.
I successfully checked out GwtFB and ran the project in GWT 2.3. However, I
I ran a script I made a couple of minutes ago and it still
I ran into a weird problem while trying to build a Traits GUI that
I ran a bundle install on my Gemfile recently, and tried to rake:db:migrate. This

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.