我想声明一个 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/