When you initialize next to a member declaration, this is only valid in C ++ 11, so if you are in C ++ 98/03, you cannot do this.
If the value never changes, you can choose constexpr static instead, and then the compiler will need to not use additional storage for the value (until you define it) and instant use constant distribution wherever the value is used.
One of the drawbacks of using the by-declaration syntax is that it must be in the header, which will recompile all translation units that include the header every time you want to change its value. If this takes a long time, this may be unacceptable.
Another difference is that using a member initialization list allows you to change the value for each constructor, while using the by-declaration version allows you to specify only one value for all constructors (although you can overwrite this value ... but I "Personally avoid this as it can become quite confusing!).
As an aside, there is no need to use new here to create an instance of Test . This is a common mistake when people come to a language from other languages, and I wanted to inform you about it. Of course, you do not need to use it outside of your example.
source share