activate RTTI in c++

后端 未结 7 1784
日久生厌
日久生厌 2020-12-09 14:37

Can anybody tell me how to activate RTTI in c++ when working on unix. I heard that it can be disabled and enabled. on my unix environment,how could i check whether RTTI is e

7条回答
  •  既然无缘
    2020-12-09 15:21

    In g++ you can test the __GXX_RTTI macro to see if RTTI is on in your code. As others have pointed out -no-rtti turns of RTTI in g++. I would bet both these things work in clang as well.

    #ifdef __GXX_RTTI
      w = dynamic_cast(FooFactory(TYPE, arg));
      if (w != NULL)
      {
        if (w->thing == OK)
          FeastOnOrangUtansAndFruitBatsAndBreakfastCereals();
      }
    #endif
    

    In newer C++ we will have access to feature testing macros __cpp_rtti and many others that will make tese things easier.

提交回复
热议问题