Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Общие вопросы > Объявление массива


Автор: Competitor 29.12.2005, 17:14
Как исправить ошибку: cannot define 'arr' as a member of managed 'Pole': mixed types are not supported. В следующем коде:
Код

#pragma once

ref class Pole
{
public:
    Pole(void);
    void CreatPole();
private:
    static const int row=10, col=10;
    int arr[row][col];
};

Автор: Romikgy 29.12.2005, 17:28
Код

class Pole
{
public:
    Pole();
    void CreatPole();
private:
    int arr[10][10];
};

Мож так?

Автор: _hunter 29.12.2005, 17:30
а лучше так:
Код

class Pole
{    
public:    
    Pole(void);    
    void CreatPole();    
private:    
    static const int row=10, col=10;    
    int arr[row][col];    
};

Автор: Void 29.12.2005, 17:48
Если это все-таки C++/CLI, то:
Код
ref class Pole {
public:
    Pole() : arr(gcnew array<int, 2>(rows, cols)) { }
private:
    static int rows = 10, cols = 10;
    array<int, 2> ^arr;
};

Автор: Competitor 29.12.2005, 20:53
Void, а как теперь обращаться к элементам этого массива? Допустим, как задать arr[4][7]=8;

Автор: pam 29.12.2005, 21:20
Или определить функцию с 2 параметрами (х, у), или класс "вектор" с функцией [], возвращающей ссылку + в классе "поле" функцию [], возвращающую ссылку на "вектор", чтобы можно было записать поле[х][у]

Код

class Pole
{
   public:
      set_cell(int, int);
...
   private:
      int **cell;
      int n_rows, n_cols; //или x_size, y_size
};


или

Код

class vector
{
   public:
      int &operator [](int x) { return row[x]; };
...
   private:
      int *row;
      int n_items; //кол-во эл-тов в "вектор"
...
};

class Pole
{
   public:
      int &operator [](int y) { return vector[y]; };
...
   private:
      vector *row;
      int n_rows; //кол-во "вектор"-ов
...
}


Удачи : )

Автор: Void 29.12.2005, 23:56
Цитата(Competitor @ 29.12.2005, 22:53)
Void, а как теперь обращаться к элементам этого массива? Допустим, как задать arr[4][7]=8;

arr[4, 7]=8;

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)