Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 1.06 KB

File metadata and controls

43 lines (31 loc) · 1.06 KB
title Compiler Warning (level 1) C4541
description Learn more about: Compiler Warning (level 1) C4541
ms.date 08/24/2025
f1_keywords
C4541
helpviewer_keywords
C4541

Compiler Warning (level 1) C4541

'operator' used on polymorphic type 'type' with /GR-; unpredictable behavior may result

Remarks

You tried to use the dynamic_cast operator or typeid operator, which requires Run-Time Type Information (RTTI), without enabling it. To enable RTTI, recompile with /GR.

Example

The following example generates C4541:

// C4541.cpp
// compile with: /W1 /GR-

#include <typeinfo>

struct Base
{
    virtual ~Base() {}
};

struct Derived : Base {};

int main()
{
    Derived derived;
    Base* pointer_to_base = &derived;

    dynamic_cast<Derived*>(pointer_to_base);   // C4541

    typeid(*pointer_to_base);   // C4541
    typeid(pointer_to_base);    // OK
}