【发布时间】:2016-10-25 05:49:52
【问题描述】:
我一直在尝试从主类中访问一系列整数,然后在方法中显示它们。
但是,由于我自己的语言不熟练,我已经在这方面遇到了一些麻烦,因为我已经很久没有编码了。
经过相当多的搜索,我找不到任何可以帮助我的东西。如果可能的话,我该怎么做呢?
#include "inventory.h"
inventory::inventory(){
int maxhealth = 100;
int maxmana = 0;
int health = 100;
int mana = 0;
int level = 1;
int agility = 1;
int strength = 1;
int healthpotions = 0;
int manapotions = 0;
int armourlevel = 0;
int weaponlevel = 0;
int crystals = 0;
int gold = 0;
int rock = 0;
int wood = 0;
}
string inventory::getinv(){
return inventory; //I know this sort of return thing won't work, just a placeholder until I figure out what to do.
}
这是我迄今为止一直在使用的,但我什至很难让它不显示“成员'X'没有在这个构造函数中初始化。”我显然做错了什么。
Inventory.h:
#ifndef INVENTORY_H_
#define INVENTORY_H_
#include <iostream>
class inventory{
private:
int maxhealth;
int maxmana;
int health;
int mana;
int level;
int agility;
int strength;
int healthpotions;
int manapotions;
int armourlevel;
int weaponlevel;
int crystals;
int gold;
int rock;
int wood;
public:
inventory();
string getinv();
};
#endif /* INVENTORY_H_ */
编辑:感谢到目前为止的帮助,我已经能够摆脱大部分错误。唯一剩下的是“..\src\zoria.cpp:1616:36: error: 'rock' was not declared in this scope”
【问题讨论】:
-
请贴一些代码说明问题。
-
..\src\inventory.cpp: At global scope: ..\src\inventory.cpp:34:23: error: no 'int inventory::getinv()' member function declared in class 'inventory' int inventory::getinv(){是我从中得到的常见错误形式。这就是你要找的东西吗? -
你需要修改它们的值还是只显示它们?
-
不足以发布
inventory类的完整定义。 -
您的问题出在
inventory.h类中,我可以通过查看您发布的错误来说明这一点。请发布,以便我指出错误。
标签: c++ class variables integer