声明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);
   ...
}

关于c++ - 通过引用将 vector 传递给函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20721585/

10-09 17:53