MSVC build errors > C2440
C2440: cannot convert
error C2440: 'initializing': cannot convert from 'const char [6]' to 'char *'
The compiler has no implicit conversion from the type of the value to the type it is assigned, returned, or cast to.
Causes and fixes
- A string literal is assigned to
char*. String literals are constant. Since conformance mode (/permissive-) is on in new projects, writeconst char*or usestd::string. - A
constpointer becomes non-const. Make the destinationconsttoo, rather than castingconstaway. - A
void*becomes a typed pointer. C++ needs an explicitstatic_cast<T*>, for example on the result ofmalloc. - An
enum classis used as an integer. Scoped enumerations do not convert implicitly: usestatic_cast<int>. - The types are unrelated. No cast makes unrelated types compatible safely: check that you use the variable you meant.
Fix C2440 with CppPilot
CppPilot reads the error, your code, and the project settings Visual Studio evaluates for the active configuration, then explains which of these causes applies. Choose Fix and the AI corrects it; CppPilot rebuilds the project and checks that the error is gone. Every change appears in Visual Studio for your approval.
Let the AI fix it in Visual Studio
CppPilot is a free extension that explains and fixes MSVC build errors with Codex, Claude, or CppPilot Cloud.
Related errors: C2664. See all guides.