dynamic_cast到泛型数组(dynamic_cast to generic array)
我收到以下错误
error C2680: 'cli::array<Type> ^' : invalid target type for dynamic_cast
在尝试编译以下代码时:
generic<typename T> static void Test() { Object^ obj = gcnew Object(); array<T>^ test = dynamic_cast<array<T>^>(obj); }
使用safe_cast可以正常工作。 有没有办法用dynamic_cast做这个,或者我必须使用safe_cast并在失败时捕获异常? 使用
as
运算符,C#很容易做到这一点。I'm getting the following error
error C2680: 'cli::array<Type> ^' : invalid target type for dynamic_cast
When trying to compile the following code:
generic<typename T> static void Test() { Object^ obj = gcnew Object(); array<T>^ test = dynamic_cast<array<T>^>(obj); }
It works fine using safe_cast. Is there no way to do this with dynamic_cast, or do I have to use safe_cast and catch the exception when it fails? C# is easily able to do this with the
as
operator.
原文:https://stackoverflow.com/questions/24253512
更新时间:2023-11-12 14:11