访问获取和设置二维数组

时间:2014-12-22 10:17:24

标签: c++ get set

我可以正确访问我的二维数组,并更改它.. 看看我的代码。
我需要使用a.getcity并希望获得citytable[ ][ ]我可以更改它

/////////////////////////////////////////////////////////////////////////


  bool checkcol_big(int fromA, int toB, int fromC,char city[][11]){
for (int i = fromA; i < toB; i++){
    if (city[fromC][i] == 'P'){
        return false;
    }
}
return true;
}


  bool checkrow_big(int fromA, int fromB, int fromC,char city[][11]){
for (int i = fromA; i <fromB; i++){
    if (city[i][fromC] == 'P'){
        return false;
    }
}
  return true;
 }

void changecity(char city[11][11], int  changerow, int changecol, int taxi)
  { 
       if (taxi == 1)
            city[changerow][changecol] = 'T1';
    else
          city[changerow][changecol] = 'T2';
  }


   Orgnizer::Orgnizer(const Taxi &taxi1, const Taxi &taxi2, City &a, Simulation &sim){
        if (sim.getOpp() == 1 || sim.getOpp() == 2)
   {
        if (sim.getFromcol() < sim.getTocol()){
        if (checkcol_big(sim.getFromcol(), sim.getTocol(), sim.getFromrow(), a.getCity)){
            if (sim.getFromrow() > sim.getTorow()){
                if (checkrow_big(sim.getFromrow(), sim.getTorow(), sim.getTocol(), a.getCity)){
                //a[sim.getTorow][sim.getTocol] == 'T1';
                    changecity(a.getCity, sim.getTorow(), sim.getTocol(), sim.getNumtaxi());

                //a[sim.getTorow][sim.getTocol] == 'T2';
              }
             }
            }
        }
  }
 }





  void City::setCity(char x[][11])

  citytable[11][11] = x[11][11];
 }

  char City::getCity() const
  {
return citytable[11][11];
  }

1 个答案:

答案 0 :(得分:0)

char* City::getCity(int x, int y)
{
 return &citytable[x][y];
}

可以这样工作。

char * to_change = getCity(x,y);
*to_change = new_value;