CppPilot

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

  1. A string literal is assigned to char*. String literals are constant. Since conformance mode (/permissive-) is on in new projects, write const char* or use std::string.
  2. A const pointer becomes non-const. Make the destination const too, rather than casting const away.
  3. A void* becomes a typed pointer. C++ needs an explicit static_cast<T*>, for example on the result of malloc.
  4. An enum class is used as an integer. Scoped enumerations do not convert implicitly: use static_cast<int>.
  5. 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.

Get CppPilot free Get started

Related errors: C2664. See all guides.