Compiler Warning (level 1) C4946
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) C4946

Error Message

reinterpret_cast used between related classes: 'class1' and 'class2'

reinterpret_cast should not be used to cast between related types. Use either static_cast or a C-style cast.

This warning is off by default. See Compiler Warnings That Are Off by Default for more information.

The following sample generates C4946:

// C4946.cpp
// compile with: /W1
#pragma warning (default : 4946)
class a {
   a() : m(0) {}
   int m;

class b : public virtual a {

class b2 : public virtual a {

class c : public b, public b2 {

int main() {
   c* pC = new c;
   a* pA = reinterpret_cast<a*>(pC);   // C4946
   // try the following line instead
   // a* pA = static_cast<a*>(pC);
© 2015 Microsoft