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

Error : no instance of constructor Repairing::Repairing matches the argument list (C++)

本文关键字:列表 C++ 匹配 参数 构造函数 错误 实例      更新时间:2023-10-16

你好,我做了一个项目,总体思路是在地图上有一些船只,它们相互交互。这是船类之一,也是主要的。

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

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向我显示没有构造函数修复的实例::修复与参数列表匹配。(此问题存在于 &小地图中)。请尽快回答

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

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

World minimap[10][10];

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

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