I can not get this program to compile, the problem lies in the method inputData. Does anyone see anything wrong it?

#ifndef JEDI_H
#define JEDI_H

#include <stdlib.h>
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

class Jedi {

public:
    Jedi(string name, int maxHealth, int currHealth, int attackBonus, int defenseBonus);
    Jedi();
    void inputData(istream& inputStream);
    //void outputData(ofstream& outputStream);
    void attack(Jedi& enemy);

    //Getters 
    int getDefenseBonus() {return defenseBonus;} ;
    int getAttackBonus() {return attackBonus;};
    int getCurrHealth() {return currHealth;};
    int getMaxHealth() {return maxHealth;};
    string getName() {return name;}
private:
    string name;
    int maxHealth, currHealth, attackBonus, defenseBonus;

    //setters
    void setDefenseBonus(int defenseBonus);
    void setAttackBonus(int attackBonus);
    void setCurrHealth(int currHealth);
    void setMaxHealth(int maxHealth);
    void setName(string name);
};
#endif  /* JEDI_H */

And here is the .cpp file

#include "Jedi.h"

Jedi::Jedi(string name, int maxHealth, int currHealth, int attackBonus, int defenseBonus) {
    setName(name);
    setMaxHealth(maxHealth);
    setCurrHealth(currHealth);
    setAttackBonus(attackBonus);
    setDefenseBonus(defenseBonus);
}

Jedi::Jedi() {

}


Jedi::inputData(istream& inputStream){
    string tempName;
    int tempMaxHealth, tempCurrHealth, tempAttackBonus, tempDefenseBonus;

    inputStream >> tempName;
    inputStream >> tempMaxHealth;
    inputStream >> tempCurrHealth;
    inputStream >> tempAttackBonus;
    inputStream >> tempDefenseBonus;

    this->Jedi(tempName, tempMaxHealth, tempCurrHealth,
            tempAttackBonus, tempDefenseBonus);
}

//Setters
void Jedi::setDefenseBonus(int defenseBonus) {this->defenseBonus = defenseBonus;}
void Jedi::setAttackBonus(int attackBonus) {this->attackBonus = attackBonus;}
void Jedi::setCurrHealth(int currHealth) {this->currHealth = currHealth;}
void Jedi::setMaxHealth(int maxHealth) {this->maxHealth = maxHealth;}
void Jedi::setName(string name) {this->name = name;}

And here is my main i'm testing the function with.

#include <iostream>
#include <fstream>
#include <string>
#include "Jedi.h"
#include <stdlib.h>

using namespace std;

int main(int argc, char** argv) {
    Jedi Bob("hi",5,5,5,5);
    cout << Bob.getName();
    cout << Bob.getAttackBonus();


    fstream jediFile;
    jediFile.open("JediList.txt");

    if(!jediFile.is_open()){
        exit(EXIT_FAILURE);
    }

    Bob.inputData(jediFile);
    return 0;
}

The inputData function has no return type(it probably should be void, since the prototype is). Also the constructor is not a member of this. Rather than trying to call the constructor you should probably have that code in a private function and call that instead.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.