将结构传递给函数时遇到问题

Running into issues when passing struct to function

本文关键字:遇到 问题 函数 结构      更新时间:2023-10-16

我正在尝试将结构传递给函数并遇到错误"'.标记之前的预期主表达式"。我不知道我将如何传递结构?任何帮助都非常感谢!

void check(std::string buildingName, int floorLevel, std::string drinkName, float drinkSize, struct machines)
{
bool correct = true;
if (buildingName == "Snell")
{
if (floorLevel == 1 || floorLevel == 3)
{
if (floorLevel == 1)
{
for (int i = 0; i < 10; i++)
{
if (machines.vendingMachines[0].drinkTypes[i].drinkName == drinkName && machines.vendingMachines[0].drinkTypes[i].drinkSize == drinkSize)
{
correct = true;
}
}
}
else
{
for (int i = 0; i < 10; i++)
{
if (machines.vendingMachines[2].drinkTypes[i].drinkName == drinkName && machines.vendingMachines[2].drinkTypes[i].drinkSize == drinkSize)
{
correct = true;
}
}
}
}
else
{
correct = false;
}
}
else
{
correct = false;
}
}

在代码的某些行中,您使用自动售货机作为机器的对象

machines.vendingMachines[2].drinkTypes[i].drinkSize

在其他一些行中,您没有使用自动售货机作为机器的对象。

vendingMachines[2].drinkTypes[i].drinkName

尽管如此,我没有看到任何声明自动售货机是结构机器的对象。