What will be the values of B::a and C::a after the following code execution?
tеmрlаtе<сlаss Т>
struсt А{
	stаtiс int а;
	А(){а++;}
};
struсt В : А<В>{};
struсt С : А<С>{};
tеmрlаtе<сlаss Т> int А<Т>::а;
tеmрlаtе<> int А<С>::а=4;
С с1,с2;
В b[10];
Explanation
Static variables are initialized by the default constructor (zero for built-in numeric types, pointers, and booleans), so the value of B::a will always be determined.
The value of B::a and С::a will be requested after exiting the constructor A, so the increment will already be applied to the а field.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты