Which of the numbered lines below contain initialization errors.
float f(int);
class Obj
{
public:
    static const int   temp1 = 7;     // 1
    static       int   temp2 = 11;    // 2
    const        int   temp3 = 13;    // 3
    static const int   temp4 = f(17); // 4
    static const float temp5 = 7.0    // 5
};
Explanation
1. Correct, the static const members can be initialized with a const value;
2. Wrong, non-const static members in-class initialization is forbidden.
3. Wrong, non-static const members should be initialized during object construction.
4. Wrong, non-const initialization of a static const member.
3. Wrong, non-integral type.

I checked the third line. The code compiles and runs without errors.

2022 Sep 19, 8:04:43 AM

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes