错误:没有构造函数修复的实例::修复与参数列表 (C++) 匹配
Error : no instance of constructor Repairing::Repairing matches the argument list (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" );`
}
很抱歉糟糕的帖子演示。我的问题是Visual Studio C++ 2010向我显示没有构造函数修复的实例::修复与参数列表匹配。(此问题存在于 &小地图中)。请尽快回答
Repairing::Repairing(World *minimap[][10], string a)
*
指示指向 World
的指针数组。
World minimap[10][10];
您传递的是World
对象的数组,而不是指针。
确定它应该是指针数组还是对象数组,并更改构造函数或变量以匹配。
相关文章:
- Pybind11:将元组列表从Python传递到C++
- 从链接列表c++中删除一个项目
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- C++如何通过用户输入删除列表元素
- 读取文件的最后一行并输入到链接列表时出错
- 复制列表初始化的隐式转换的等级是多少
- LNK2038、MSVS2017 MAGMA的原因列表
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 没有为自己的结构调用列表推回方法
- 使用简单类型列表实现的指数编译时间.为什么
- 一对向量构造函数:初始值设定项列表与显式构造
- 标准是否使用多余的大括号(例如 T{{{10}}})定义列表初始化?
- 通过for循环使用用户输入填充列表
- C++:如何使函数只返回作为列表一部分的字符串
- 概念中的cv限定符需要表达式参数列表
- 下面是我为检测链接列表中的循环而制作的代码
- 建议在运行时将带有类实例的列表从c++导入qml
- 如何维护资源管理器项目视图中当前可见的项目列表
- 在卡萨布兰卡形成编码参数的列表
- 在没有参数列表的情况下使用模板名称"Event"无效,模板问题