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 {

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

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

    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) {

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);

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;


    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.

This article has been dead for over six months. Start a new discussion instead.