c++ - 将结构传递给函数时遇到问题
问题描述
我正在尝试将结构传递给函数并遇到错误“预期的主表达式之前'。' 令牌”。我无法弄清楚我将如何传递结构?任何帮助深表感谢!
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;
}
}
解决方案
在您的代码的某些行中,您使用 vendingMachines 作为 Machines 的对象
machines.vendingMachines[2].drinkTypes[i].drinkSize
在其他一些行中,您没有使用 vendingMachines 作为 Machines 的对象
vendingMachines[2].drinkTypes[i].drinkName
尽管如此,我没有看到任何声明 VendingMachines 是结构机器的对象。
推荐阅读
- laravel - 使用外键访问 Laravel 中的 3 个表(laravel 6)
- python - 如何在没有随机导入的情况下在海龟中获得独特和随机的颜色
- neo4j - Neo4j 桌面 - 远程图形存储在哪里?
- sql - 如何在 postgresql 的一列中显示多个字段?
- java - 需要从 Firebase 检索到的消息文本和时间大小不同,但最终在相同的 TextView 中
- php - 为什么 array_pop() 在 foreach 循环中不起作用?
- gcc - 如何在 pip 命令中指定 gcc 路径?
- powershell - 为什么返回 -2
- python - 更改矩阵中一个元素的数据类型
- excel - Excel:范围内排名/顶部的文本值