Avatar ·

How to properly define a static const std::string in a C++ class?

Hi everyone! I started learning C++ and encountered a problem when working with static constants in a class. I need to define a static data member of type `const std::string` inside a class. Here is my code: ```cpp #include class MyClass { public: static const std::string kAppName = "MyApp"; // Error! }; ``` The compiler gives an error: "error: 'const std::string kAppName' cannot be initialized by a constant expression" or something like "non-const static data member must be initialized out of line". I know that for integer types (int, char, etc.) and enum you can initialize directly in the class, but for std::string this does not work. I tried different options: removed const, added constexpr, but nothing helps. Online sources say that you need to define the static