错误:没有构造函数的实例修复::修复匹配参数列表(C ++)

时间:2015-01-15 16:16:13

标签: c++ class pointers

您好我做了一个项目,其中一般的想法是让一些船只在地图中互相交流。这是船类和主要船舶之一。

类修复:(包括我需要的头文件)

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" );`

}

抱歉糟糕的帖子演示。我的问题是Visual Studio C ++ 2010向我显示没有构造函数的实例修复::修复匹配参数列表。(此问题存在于&amp; minimap中).PLease answer as as尽快

1 个答案:

答案 0 :(得分:2)

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

*表示指向World的指针数组。

World minimap[10][10];

您传递的是World个对象数组,而不是指针。

确定它是否应该是指针或对象的数组,并更改构造函数或变量以匹配。