dynamic_cast" used in polymorphic classes with /GR-

Visual studio 2019 compiles UE4 error: error C4541: "dynamic_cast" is used on the polymorphic type "***" with /GR-; a solution that may cause unpredictable behavior

reason

  1. Using dynamic_cast<> will use RTTI technology, so the option "type information at runtime" needs to be enabled. /GR-means to turn off RTTI technology, /GR means to turn on RTTI technology
  2. UE4 turns off RTTI by default

Solution

  1. Open the project properties in vs2019->C/C+±>language, on the right side of the "Enable Runtime Type Information" item, select "Yes/GR", as shown in the figure
    insert image description here

  2. UE4 disables RTTI by default. If you want to use dynamic_cast, you need to enable rtti in build.cs; as shown in the figure
    insert image description here

Guess you like

Origin blog.csdn.net/xwb_12340/article/details/118578268