简体   繁体   English

如何声明handel数组?

[英]How to declare array of handel?

I want to declare an array of handel as the following code: 我想将handel数组声明为以下代码:

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

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

But it threw error when compiling 但是编译时抛出错误

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 ^[]'

Someone can tell me the correctly way to declare an array of handel? 有人可以告诉我声明handel数组的正确方法吗?

Many thanks! 非常感谢!

T&TGroup T&T集团

You need to use gcnew since this a .Net array, not a C++ array since this is an array of a managed type, not an array of a native type. 您需要使用gcnew 因为这是一个.Net数组,而不是C ++数组, 因为这是托管类型的数组,而不是本机类型的数组。 I don't have a compiler handy to test this code, but I believe this would be the way to do it. 我没有方便的编译器来测试此代码,但我相信这是做到这一点的方法。

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

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

I would probably use a generic collection type instead of an array. 我可能会使用通用集合类型而不是数组。

Not sure what a handel is, though. 不过,不确定什么是handel。

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

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