Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何声明handel的数组?_C++_.net_Arrays_Collections_C++ Cli - Fatal编程技术网

C++ 如何声明handel的数组?

C++ 如何声明handel的数组?,c++,.net,arrays,collections,c++-cli,C++,.net,Arrays,Collections,C++ Cli,我想将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 C

我想将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组

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


不过,我不确定handel是什么。

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


不确定汉德尔是什么。虽然,< A/P> < P>你需要使用<代码> GCNEX< /COD>这是.NET数组,而不是C++数组,因为这是托管类型的数组,而不是本机类型的数组。我手头没有一个编译器来测试这段代码,但我相信这是一种方法

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

public:
    B()
    {
        b = gcnew array<Bitmap^>(10);
    }
};
使用名称空间系统::绘图;
参考B类
{
私人:
数组^b;
公众:
B()
{
b=新阵列(10);
}
};

< Actudio> 您需要使用<代码> GCNEX< /C>。因为这是.NET数组,而不是C++数组,因为这是托管类型的数组,而不是本机类型的数组。我手头没有一个编译器来测试这段代码,但我相信这是一种方法

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

public:
    B()
    {
        b = gcnew array<Bitmap^>(10);
    }
};
使用名称空间系统::绘图;
参考B类
{
私人:
数组^b;
公众:
B()
{
b=新阵列(10);
}
};

我更喜欢莫扎特的作品,而不是汉德尔的作品。你是说handle吗?String handelworks[]={“尼禄”、“阿尔米拉”、“弥赛亚”}:)只是个玩笑。我建议你用谷歌搜索你的第一个错误来发现问题。您将在这里找到解决方案:您不能在非托管数组中存储托管对象引用。垃圾收集器将无法找到它们。使用array关键字。我更喜欢莫扎特的数组,而不是汉德尔的数组。你是说handle吗?String handelworks[]={“尼禄”、“阿尔米拉”、“弥赛亚”}:)只是个玩笑。我建议你用谷歌搜索你的第一个错误来发现问题。您将在这里找到解决方案:您不能在非托管数组中存储托管对象引用。垃圾收集器将无法找到它们。使用数组关键字。需要是
数组^b@crashmstr抓得好。我想,在未经测试的帖子中,我肯定会遇到一些类似的事情。它现在已修复。需要是
数组^b@crashmstr抓得好。我想,在未经测试的帖子中,我肯定会遇到一些类似的事情。现在已经修好了。