2015-01-15 39 views
-5

你好我已經做了一個項目,其中的一般想法是在地圖上有一些船隻,他們互相交互。這裏有一個船類和主要。錯誤:沒有構造函數的實例修復::修復匹配參數列表(C++)

類修復:(包括頭文件,我需要)

Repairing::Repairing(World *minimap[][10], string a) 
{ 
    int temp1, temp2; 
    bool done = false; 

    totalgoldtraded=0; 
    totalgoldearned=0; 
    totaldmgdone=0; 
    totaldmgtaken=0; 
    totalmove=0; 
    reserve = 0; 
    maxStamina = 100; 
    stamina = 100; 
    speed = 2; 
    isPirate = false; 
    name = a; 

    srand(time(0)); 

    while(done != true) 
    { 
     temp1 = (rand()%10); 
     temp2 = (rand()%10); 

     if((minimap[temp1][temp2]->checkShip() == false) && (minimap[temp1][temp2]->checkHarbor() == false) && (minimap[temp1][temp2]->getTreasure() == false)) 
     { 
      posX = temp1; 
      posY = temp2; 
      minimap[temp1][temp2]->setShip(true); 
      done = true; 
     } 
    } 
} 

void Repairing::operation(Boat *ships[], World *minimap[][10]) 
{ 
    int temp; 

    if (posX-1>=0) 
    { 
     for (int i=0; i<8; i++) 
     { 
      if (ships[i]->getPosX() == posX-1 && ships[i]->getPosY() == posY) 
      { 
       ships[i]->setStamina(10); 

       temp = ships[i]->getReserve(); 
       temp /= -10; 
       totalgoldearned -= temp; 
       ships[i]->setReserve(temp); 

       temp *= -1; 
       reserve += temp; 
       cout << "The " << name << " ship has earned gold from repairing. " << endl; 
      } 

      break; 

     } 
    } 

    if (posX+1<=9) 
    { 
     for (int i=0; i<8; i++) 
     { 
      if (ships[i]->getPosX() == posX+1 && ships[i]->getPosY() == posY) 
      { 
       ships[i]->setStamina(10); 

       temp = ships[i]->getReserve(); 
       temp /= -10; 
       totalgoldearned -= temp; 
       ships[i]->setReserve(temp); 

       temp *= -1; 
       reserve += temp; 
       cout << "The " << name << " ship has earned gold from repairing." << endl; 
      } 

      break; 

     } 
    } 

    if (posY-1>=0) 
    { 
     for (int i=0; i<8; i++) 
     { 
      if (ships[i]->getPosY() == posY-1 && ships[i]->getPosX() == posX) 
      { 
       ships[i]->setStamina(10); 

       temp = ships[i]->getReserve(); 
       temp /= -10; 
       totalgoldearned -= temp; 
       ships[i]->setReserve(temp); 

       temp *= -1; 
       reserve += temp; 
       cout << "The " << name << " ship has earned gold from repairing. " << endl; 
      } 

      break; 

     } 
    } 

    if (posY+1<=9) 
    { 
     for (int i=0; i<8; i++) 
     { 
      if (ships[i]->getPosY() == posY+1 && ships[i]->getPosX() == posX) 
      { 
       ships[i]->setStamina(10); 

       temp = ships[i]->getReserve(); 
       temp /= -10; 
       totalgoldearned -= temp; 
       ships[i]->setReserve(temp); 

       temp *= -1; 
       reserve += temp; 
       cout << "The " << name << " ship has earned gold from repairing." << endl; 
      } 

      break; 

     } 
    } 

} 
` 

,這裏是主要的:

int randNumber(int x) 
{ 
    int temp; 

    temp = rand()%x + 1; 
    return temp; 
} 

int main() 
{ 
    srand((unsigned)time(0)); //Thats a must for our random numbers! 

    int i, j, temp; 
    World minimap[10][10]; //Array with World objects! 
    Boat *ships[8]; // Array that points the boat objects! 


    for(i=0; i<10; i++) //Initialize the World Array Objects! 
    { 
     for(j=0; j<10; j++) 
     { 
      temp = randNumber(10); 
      minimap[i][j].setProperties(temp); 
      cout << minimap[i][j].getWeather() << endl; 
     } 
    } 

    Repairing pirate_one(&minimap, "First Pirate"); 
    //Exploring ex(minimap, "First Exploring");` 

} 

遺憾的壞後presentation.My問題是,Visual Studio的C++ 2010顯示我沒有構造函數Repairing :: Repairing的實例匹配參數列表(此問題存在於& minimap中)。儘快解答

+3

_「請儘快回答」_ Monster DV磁鐵。 – 2015-01-15 16:18:58

+0

你沒有清楚描述你的問題。我甚至無法理解這個問題以及你所嘗試過的。一個權利,它失蹤了。 Downvoting。 – usr1234567 2015-01-15 16:20:24

+0

修復了 – 2015-01-15 16:28:31

回答

1
Repairing::Repairing(World *minimap[][10], string a) 

*表示指向World的指針數組。

World minimap[10][10]; 

你傳遞World對象,而不是一個指針數組。

決定它是否應該是指針或對象的數組,並更改構造函數或變量以匹配。

相關問題