admin管理员组文章数量:1405170
I tried to include in my project .h file, but i dont know how to use it right. I use VS22 and it doesnt give me quick fixes.
Inventory.cpp
#include <iostream>
#include <string>
#include "Inventory.h"
using namespace std;
const unsigned int inventoryCapacity = 10;
int itemsCount;
string inventoryObjects[inventoryCapacity];
namespace BP {
bool isInvFull()
{
if (itemsCount == 10)
{
return true;
}
else {
return false;
}
}
void main() {
try {
throw exception("Exception");
}
catch (...) {
cout << "Exception!" << endl;
}
}
void openInventory()
{
itemsCount = sizeof(inventoryObjects);
cout << "items in your backpack:\n";
if (!isInvEmpty())
{
for (int i = 0; i < itemsCount; i++)
{
cout << inventoryObjects[i] << "\n" << endl;
}
cout << "Items: " << itemsCount << "/" << inventoryCapacity << ".";
if (isInvFull())
{
cout << " Your inventory is full.\n" << endl;
}
else {
cout << ".\n" << endl;
}
}
else {
cout << "Your Inventory is empty...\n" << endl;
}
}
bool isInvEmpty()
{
if (itemsCount == 0)
{
return true;
}
else {
return false;
}
}
void giveItem(string itemName)
{
if (!isInvEmpty()) { //Error there C3861
int currentItem = sizeof(inventoryObjects);
inventoryObjects[currentItem + 1] = itemName;
cout << "Item \'" << itemName << "\' given!\n" << endl;
}
else {
cout << "Inventory is full!\n" << endl;
}
}
}
main.cpp
#include <string>
#include <iostream>
#include "Inventory.cpp"
using namespace std;
using namespace BP;
const string COMMAND_LIST[] = {"help", "inventory", "cls", "giveitem", "givemoney", "delitem", "delmoney"};
int commandsCount = sizeof(COMMAND_LIST);
string input;
string itemName;
int main() {
giveItem("Sword");
while (true)
{
cin >> input;
if (input == "help") {
for (int i = 0; i < commandsCount; i++)
{
cout << COMMAND_LIST[i] << "\n" << endl;
}
}
else if (input == "inventory") {
openInventory();
}
else if (input == "cls") {
system("cls");
}
else if ("giveitem") {
cout << "Item name: ";
cin >> itemName;
giveItem(itemName);
}
}
return 0;
}
I just do something and now I have only one error (See post title).
Before: 2 with isInvFull 2 with isInvEmpty
Also I have 2 yellow flags:
Reading invalid data from 'inventoryObjects': the readable size is '400' bytes, but '16080' bytes may be read. C6385
C6305
All of them in 63 row
本文标签:
版权声明:本文标题:c++ - I have C3861 (isInvEmpty: Identifier not found) in Inventory.cpp (37), but function is there - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744290767a2599100.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论