c ++使用CLI数组初始化值static int

时间:2015-06-19 19:05:38

标签: c++ arrays class static command-line-interface

所以我有2个数组都是2维cli ::数组。 什么是初始化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

1 个答案:

答案 0 :(得分:0)

所以我用静态构造函数修复了问题,我注意到你应该输入[0,0]而不是[0] [0]。我习惯了普通的C数组。

//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]
static Cords() {         //static constructor to initialize values
      Xcord[0,0] = 4234; // [0,0] instead of [0][0]
      Ycord[0,0] = 2342;
      ...
    }
public:
     Cords();
     static int getX(void);
     static int getY(void);
};