如何声明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 ^[]'
有人能正确地告诉我的方式来声明亨德尔的数组时,它抛出的错误?
非常感谢!
牛逼& T组
答
您需要使用gcnew
因为这是一个.Net数组,而不是一个C++数组
,因为这是一个托管类型的数组,而不是一个本机类型的数组。我没有一个方便测试此代码的编译器,但我相信这将是实现它的方法。
using namespace System::Drawing;
ref class B
{
private:
array<Bitmap^>^ b;
public:
B()
{
b = gcnew array<Bitmap^>(10);
}
};
答
我可能会使用泛型集合类型,而不是一个数组。
不知道什么是汉德尔。
我宁愿有一个莫扎特而不是亨德尔。你的意思是处理? – crashmstr 2012-03-30 18:15:17
String handelsWorks [] = {“Nero”,“Almira”,“弥赛亚”} :)只是一个笑话。 – Almo 2012-03-30 18:15:59
此外,我建议只是使用谷歌搜索你的第一个错误,看看问题。您将在这里引导解决方案:http://*.com/questions/995434/arrays-of-strings-in-managed-c – 2012-03-30 18:22:27