C++/CLI-Question: Is there an equivalent to the C# “is” keyword or do I have to use reflection?

后端 未结 3 1091
不知归路
不知归路 2021-01-01 23:38

I\'ve read somewhere on MSDN that the equivalent to C#\'s \"is\" keyword would be dynamic_cast, but that\'s not really equivalent: It doesn\'t work with value types or with

3条回答
  •  时光取名叫无心
    2021-01-02 00:12

    You can use safe_cast where you would use dynamic_cast in native C++ and trap the System::InvalidCastException. In terms of compatible types the semantics of asking if you can convert types could pick up a broader range of types than checking identity. You may actually want the added flexibility of IsAssignableFrom.

    I don't think there's an efficient equivalent to the good old dynamic_cast idiom we're used to, certainly nothing as compact.

提交回复
热议问题