我的getter函数中的EXC_BAD_ACCESS代码= 1

时间:2017-12-02 23:08:30

标签: c++ xcode

由于错误“EXC_BAD_ACCESS(code = 1,address = 0x0)”,我的代码将无法运行。我以前遇到过这个错误,但它总是试图在数组或向量中调用一些超出范围的东西,但是这只是一个简单的getter函数,我似乎无法弄清楚问题是什么。

这是我的.h文件

use

这是我的.cpp文件

#ifndef Attack_h
#define Attack_h

#include <stdio.h>
#include <string>
#include <iostream>
#include <vector>
#include "stdlib.h"
#include <algorithm>
#include <fstream>
using namespace std;

class Attack{
public:
    string nameOfAttack;                    //name of an attack
    string effect[3];                       //effect of attaick if         applicable
    int damage;                             //the amount of damage an         attack does
    vector<string> cost;                    //the attack cost of an attack in strings of type of energy
    int amount;                             //amount of energy needed for attack

public:
    Attack();                               //default constructor
    Attack(string);                         //constructor for an attack     with just its name
    Attack(string, int);                    //constructor for an attack with its name and damage
    Attack(string,string);                  //constructor for an attack with its name and effect
    Attack(string, string, int);            //constructor for an attack with its name, effet, and damage

    void setCost(vector<string>, int);      //sets the attaco cost in the vector string array, with the number of energy cost
    string getCost();                       //returns the attack cost of an attack
    int getCostNum();
    string getCost(int);

    void setDamage(int);                    //sets the damage of an attack
    int getDamage();                        //returns the damage of an attack

    void setEffect(string[3]);                 //sets the effect of the attack
    string getEffect();                     //returns the effect of the attack

    void setName(string);                   //mutator for the name of the attack
    string getName();                       //returns the name of the attack

};
#endif /* Attack_h */

0 个答案:

没有答案