C ++ initializes static int values ​​with CLI array

So, I have 2 arrays which are 2 dimensional cli :: arrays. What's the correct syntax to initialize cli :: array. I tried in the example below but it doesn't work.

//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

      

+3


source to share


1 answer


So I fixed the static constructor problem and I noticed that you have to enter [0,0] instead of [0] [0]. I'm used to regular C arrays.



//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);
};

      

0


source







All Articles