通过函数通过引用传递向量

Passing a vector by reference through a function

本文关键字:向量 引用 函数      更新时间:2023-10-16

我在声明 fillVector 的参数时收到"参数 1 处的类型/值不匹配"错误。是否存在命名空间问题或只是某处语法错误?

#ifndef VECTOR_OBJECTS_H_INCLUDED
#define VECTOR_OBJECTS_H_INCLUDED

void fillVector(vector<Chest> &newChest, int x, int y)
{
ifstream load_chest;
load_chest.open("\chest_item_inputs.txt");
char input = NULL;
int x_count = NULL;
int y_count = NULL;
while(input != 0)
{
load_chest >> input;
    if(input = '.')
    {
    x_count++;
    }
    if(input = 'C')
    {
    x = x_count;
    y = y_count;
    Chest newChest(x_count, y_count);
    newChest.pushback(newChest);
    }
    if(input = 80)
    {
    x_count = 0;
    y_count++;
    }
} load_chest.seekg (0, load_chest.beg);
}
}
#endif // VECTOR_OBJECTS_H_INCLUDED

您有一个与参数同名的局部变量:

void fillVector(vector<Chest> &newChest, int x, int y) {
   ...
   Chest newChest(x_count, y_count);
   newChest.pushback(newChest);
   ...
}