繁体   English   中英

如何声明handel数组?

[英]How to declare array of handel?

我想将handel数组声明为以下代码:

using namespace System::Drawing;
ref class B 
{
    Bitmap^ b[];

    B()
    {
        b = new Bitmap^[10];
    }
};

但是编译时抛出错误

error C2728: 'System::Drawing::Bitmap ^' : a native array cannot contain this managed type
error C4368: cannot define 'b' as a member of managed 'B': mixed types are not supported
error C2728: 'System::Drawing::Bitmap ^' : a native array cannot contain this managed type
error C2440: '=' : cannot convert from 'System::Drawing::Bitmap ^*' to 'System::Drawing::Bitmap ^[]'

有人可以告诉我声明handel数组的正确方法吗?

非常感谢!

T&T集团

您需要使用gcnew 因为这是一个.Net数组,而不是C ++数组, 因为这是托管类型的数组,而不是本机类型的数组。 我没有方便的编译器来测试此代码,但我相信这是做到这一点的方法。

using namespace System::Drawing;
ref class B 
{
private:
    array<Bitmap^>^ b;

public:
    B()
    {
        b = gcnew array<Bitmap^>(10);
    }
};

我可能会使用通用集合类型而不是数组。

不过,不确定什么是handel。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM