


In C++20 or under /Zc:char8_t, a UTF-8 literal character or string (such as u8'a' or u8"String") is of type const char8_t or const char8_t, respectively. Conversion from string literal loses const qualifier (see error C2440: 'initializing' : cannot convert from 'const char ' Build: cl /Zc:strictStrings /W3 C2440s.cpp This sample generates C2440: // C2440s.cpp In C, the type of a string literal is array of char, but in C++, it's array of const char. Examples C++ string literals are constĬ2440 can be caused if you attempt to initialize a non-const char* (or wchar_t*) by using a string literal in C++ code, when the compiler conformance option /Zc:strictStrings is set. We've listed some common ones in the Examples section.

There are many ways to generate this error. The compiler generates C2440 when it can't convert from one type to another, either implicitly or by using the specified cast or conversion operator. The compiler can't implicitly convert from *type1* to *type2*, or can't use the specified cast or conversion operator. ' conversion' : cannot convert from ' type1' to ' type2' ' initializing' : cannot convert from ' type1' to ' type2'
