구조를 읽는 동안 처리되지 않은 예외
문제
프로그램은이 줄에 대한 처리되지 않은 예외를 throw합니다.
}else if(s == "backpack"){
cout << "\nEquipped items: " << endl;
cout << weapon->Name << endl << cArmour->Name << endl; //this line
.
장비 된 항목 : '을 인쇄 한 다음 예외를 던졌습니다.이 파일 - Player.h - Library.h가 포함되어 있으며, 구조체가있는 globals.h가 포함됩니다.
struct sWeapon{
std::string Name;
int Damage;
};
struct sArmour{
std::string Name;
int AP;
};
.
플레이어 생성자에서 구조체 객체가 생성됩니다.
Player::Player(std::map<std::string,sWeapon*> wepArray,std::map<std::string,sArmour*> armArray){
weapons = wepArray;
armour = armArray;
weapon = wepArray["None"];
cArmour = armArray["None"];
}
.
전체 프로그램의 시작 부분에서 init_weapons 및 init_armour를 호출합니다.
int main(){
using namespace std;
//initialise the game
std::map<std::string,sWeapon*> wepArray = init_weapons(); //get weapon array
std::map<std::string,sArmour*>armArray = init_armour(); //get armour array
.
모든 무기의지도를 반환합니다 :
//init_weapons()
//sets up weapons map
std::map<std::string,sWeapon*> init_weapons(void){
std::map< std::string, sWeapon* > weapons; //map of weapons
//starting 'none'
sWeapon* none = new sWeapon();
none->Name = "None";
none->Damage = 0;
//create weapons
sWeapon* w1 = new sWeapon();
w1->Name = "Rusty dagger";
w1->Damage = 3;
//put in map
weapons[w1->Name] = w1;
return weapons;
}
std::map<std::string,sArmour*> init_armour(void){
std::map< std::string, sArmour* > armour; //map of armour
//starting 'none'
sArmour* none = new sArmour();
none->Name = "None";
none->AP = 0;
//create armour
sArmour* a1 = new sArmour();
a1->Name = "Leather";
a1->AP = 10;
//put in map
armour[a1->Name] = a1;
return armour;
}
.
그런 다음 맵을 플레이어 생성자에 인수로 전달합니다. 해결책
weapon
또는 cArmour
가 null이거나 아무데도 없음을 추측합니다.
당신이 당신의 글로벌 해시에 "없음"무기와 갑옷을 저장하지 않기 때문에
해당 두 "없음"오브젝트의 포인터를 인쇄 해보십시오. 그런 다음 객체 멤버 weapon
또는 cArmour
의 포인터 값을 인쇄 해보십시오.
제휴하지 않습니다 StackOverflow