c++ - Regarding empty initialisation of static array of class types -


when ran static code analyzer qacpp, got warning. according qacpp documentation, initializing {0} works built in types. initialize array of objects of type a, {} must used. below:

int i[5] = {0};  // works built-in types.   a[5] = {};   // ok, works both built-in , class types 

is standard c++ rule? according this, array of pointers class type must initialized {}, right?

does statement:

a* ap[5] = {} 

initialise 5 pointers null?

qacpp throws me warning when used a* ap[5] = {null}, though code compiles , works otherwise.


additional

i think warning more because array static.

and here explanation found in documentation:

there many problems use of objects static storage duration, particularly declared outside of functions. if many functions can access static object situation may become difficult maintain. also, in case of multi-threaded applications becomes necessary protect mutex each static object can accessed concurrently. therefore idea limit scope of static object as possible, know such object accessed.

namespace or class objects static storage duration initialised @ start of program, before calling main(), , order of initialisation unspecified. reliance on order of initialisation may lead objects being used before initialised. if exception thrown result of initialising non-local object program terminate.

block scope objects static storage duration initialised when function first called. therefore, best use singleton pattern instead of namespace objects , static data members. entails wrapping object in function local static object, , having function return reference object.

yes, standard rule. array aggregate. rules of initialization explicitly mentioned in standard aggregates.

does statement: a* ap[5] = {} intialise 5 pointers null?

yes

qacpp throws me warning when used a* ap[5] = {null}

what warning? maybe warning initialized first element, , others stay null. of course, may need. then, compiler warning :)

i think question , answer interesting. what aggregates , pods , how/why special?


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -