Is there a construct like Java initializing blocks in C++?
c++, java
Solution
It needs to be pointed out that there are two different forms of initialization blocks in Java. The bare `{...}` block, without the keyword `static`, is just a bit of compiler swizzling -- the text in the block is appended to the front of any constructors that are defined -- no separate code segment is generated. A block that begins `static {...`, on the other hand, is a static initialization block and a (semi-)proper procedure in its own right (named, not surprisingly, "static").
The `static` block is executed only once, immediately (with a few caveats) after the class is loaded. The non-static initializer is (by virtue of being copied into the constructors) executed every time a constructor is executed, and hence is generally inappropriate for static init.
Problem
I read in some articles that there is something called Initializing blocks in java ; where we can perform some initializing assignments When the Class is loaded or an instance is created. Apart from methods and constructors, Initialization Blocks are the third place in a Java Program where operations can be performed. ``` class InitDemo { static int y; int x; { y = 10; x = 0; } } ``` I am asking if there is such paradigme in C++ ? Thank you.