why can’t i define a static field in the declaration?

Why I can’t define a static field in the declaration?

You can!

#include <string>

class MyClass
{
    static inline std::string name = "Whatever";
    //     ^^^^^^
};

Isn’t name private by default? Then why can I change its value from outside the class?

You can’t!

You’re defining/initialising it, not changing its value.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top