Compiler Warning (level 1) C4407
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Compiler Warning (level 1) C4407

Error Message

cast between different pointer to member representations, compiler may generate incorrect code

An incorrect cast was detected.

C4407 can be generated because of compiler conformance work that was done in Visual C++ 2005; pointer-to-members now require qualified name and &. For more information, see Breaking Breaking Changes in the Visual C++ 2005 Compiler.

C4407 can occur if you cast between a multiple inheritance pointer-to-member to a single inheritance pointer-to-member. Sometimes this can work, but sometimes it can’t because the single inheritance pointer-to-member representation doesn’t hold sufficient information. Compiling with the /vmm might help (see /vmm, /vms, /vmv (General Purpose Representation) for more information). You can also try rearranging your base classes; the compiler is detecting a loss of information in the conversion because a base class is at a non-zero offset from the derived.

The following sample generates C4407:

// C4407.cpp
// compile with: /W1 /c
struct C1 {};
struct C2 {};
struct C3 : C1, C2 {};

typedef void(C3::*PMF_C3)();
typedef void(C2::*PMF_C2)();

PMF_C2 f1(PMF_C3 pmf) {
   return (PMF_C2)pmf;   // C4407, change type of cast,
   // or reverse base class inheritance of C3 (i.e. : C2, C1)
© 2016 Microsoft