库存构建
Inventory Building
本文关键字:构建 更新时间:2023-10-16
这是我将CD添加到库存的代码。我添加了它,但当我选择显示库存选项时,它不会显示在那里。
void addCD(Inventory i) {
int isbn = readIsbn();
if ( isbn ) {
char buffer[BUF_SIZE];
cout << "CD title: ";
cin.getline(buffer,BUF_SIZE);
string title(buffer);
cout << "Developer name: ";
cin.getline(buffer,BUF_SIZE);
string developer(buffer);
CD new_CD(isbn,title,developer);
i.addItem(new_CD);
}
addItem的函数定义如下:
Inventory::addItem(Item& new_item) {
// Lookup item in inventory
ItemTable::const_iterator i = _table.find(new_item.getIsbn());
if ( i == _table.end() ) {
Item *ptrItem = new_item.clone();
_table[ptrItem->getIsbn()] = ptrItem;
} else {
cout << "Warning: Item with isbn " << new_item.getIsbn()
<< " already exists" << endl;
}
}
没有错误,只是库存没有显示新添加的项目。
对于函数void addCD(Inventory i)
,传递参数的副本,修改参数i
不会影响调用方传递的内容。
您应该使用引用让函数修改调用者的局部变量。
尝试使用void addCD(Inventory &i)
而不是void addCD(Inventory i)
。(添加&
)
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- 无法在 CLion 中构建 C++ 项目
- 函数向量_指针有不同的原型,我可以构建一个吗
- 如何使用ndk-build.cmd构建Android.so文件
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- VSCode-有一个红色下划线,但程序构建和运行正确,并且出现配音错误
- 构建可组合有向图(扫描仪生成器的汤普森构造算法)
- 无法使用Qt Creator在Windows中构建yaml-cpp
- 构建一个由C和C++文件组成的库
- llvm构建器向基本块添加终止符
- FLTK 2.0构建和演示,适用于VS2019的2011年左右的代码库
- 如何跨平台将二进制资源构建到程序中?
- 将 OpenCV 与 CMAKE 中的项目一起构建为第三方库的正确方法
- 如何解决 Ninja c++ 构建和执行问题
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- CMake WxWidgets项目成功地在Linux上构建,但没有在Windows上构建
- 更改命令行 qt5 源代码构建配置的正确/快速方法
- 用CMake构建C++协议
- Mingw-64 在构建和安装后不会编译 openCV 代码