c++ - Which initialization of a static variable is correct -



c++ - Which initialization of a static variable is correct -

i have static variable in header. example:

header file:

class fruits{ public: static int colour; }

at cpp file after including header, improve write:

int fruits::colour=1;

or

int fruits::colour(1);

someone told me first not initialization of variable declaration of another. right way , place set initialization?

when c++ beingness designed decided that, maintain consistency before code, type x = y; considered equivalent type x(y); for built-in types. 2 examples of static initialisation give hence treated utterly identical compiler , different ways of writing same thing.

for classes, becomes more complicated. in many cases, type x = y , type x(y) interchangeable, however, there circumstances in result in different results. discussed, @ length, in answers this question.

c++

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -