c++ - 如何声明 handel 数组?

标签 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 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 数组的正确方法?

非常感谢!

大统华

最佳答案

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

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

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

关于c++ - 如何声明 handel 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9948325/

相关文章:

.net - 为什么这里的 fastmember 看起来并不比反射快?

c# - 如何比较不区分大小写和不区分重音的字符串

php - 一次检查所有数组值

c++ - 使用 C++ 模板的矩阵乘法

c++ - OMSetRenderTargets 只呈现第一个提供的目标

c# - .NET 4.0 比早期版本慢,这是真的吗?

java - Java中将数据实时存储在二维数组中

c++ - 当比较两个不同的字符串时,C++ 正在比较什么?

c++ - 如何包装抽象类的指针列表?

python - append 到文件并使用数组时出错