通过函数通过引用传递向量
Passing a vector by reference through a function
我在声明 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<reference_wrapper> 的元素删除引用的值<T>不会使向量无效?
- 通过引用传递向量是请求 std::分配器
- 从类返回引用向量
- 返回两个向量 – 使用引用还是元组?
- 在C++中通过引用传递向量数组
- 引用向量中的特定索引
- 如何告诉自动推断向量<bool>元素的非引用类型
- 如何在方法主体中返回声明向量的引用?
- 向量引用C++
- 在向量引用上调用 vector::reserve()
- 如何创建一个同时接受数组和向量引用的函数模板
- 如何做列表的向量引用列表中的值
- c++向量引用转换
- 最方便的表示向量引用的向量的方法