c++ - 通过函数按引用传递 vector

标签 c++ vector

我在声明 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/

相关文章:

c++ - 使用 std::vector 作为原始内存的 View

C++:合并两个以元组为元素的 vector

c++ - 查找 vector 中最接近的值

c++ - 读取大型 txt 文件时在结构内动态分配 vector

c++ - 显示打开文件中的文本

python - 编译 python 代码并将其链接到 C++ 程序?

c++ - 基本的新建/删除运算符(operator)日志记录

r - 在 R 中添加多个向量

c++ - 返回本地是否还涉及为返回创建临时文件?

c++ - 在 MVC 设计中避免与 C++ 的循环依赖