【发布时间】:2015-09-05 20:58:07
【问题描述】:
所以我有 2 个数组都是二维 cli::arrays。 初始化 cli::array 的正确语法是什么。我在下面的示例中进行了尝试,但不起作用。
//Cords.h
ref class Cords {
private:
static array<int,2>^ Xcord = gcnew array<int,2>(4,4); // [4][4]
static array<int,2>^ Ycord = gcnew array<int,2>(4,4); // [4][4]
public:
Cords();
static int getX(void);
static int getY(void);
};
int Cords::Xcord[0][0] = 4234; //On these lines is the mistake
int Cords::Ycord[0][0] = 2342; //On these lines is the mistake
【问题讨论】:
-
.NET 数组总是初始化为零。您可以使用“类型初始化器”来预加载其他值。
-
你能举个例子吗?
-
参见 MSDN 上的示例:msdn.microsoft.com/en-us/library/…
-
@saito ,不要将静态字段私有化,并在不同的范围(区域)中承载该字段。并在将值赋值给变量之前删除 int。
标签: c++ arrays class static command-line-interface