Hi, I'm really struggling with C++ and after doing some googling I've yet to figure out a way to fix the errors I'm getting. If someone could please help me figure out how to fix these I'd really appreciate it. This is my code so far:
Main CPP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream>
#include <string>
#include "Jogger.h"
using namespace std;
int main() {
string name;
int walk;
int jog;
int run;
cout << "Enter your name: ";
cin >> name;
cout << "Enter your miles walked: ";
cin >> walk;
cout << "Enter your miles jogged: ";
cin >> jog;
cout << "Enter your miles ran: ";
cin >> run;
Jogger Jogger_2;
Jogger_2.setName(name);
Jogger_2.setWalk(walk);
Jogger_2.setJog(jog);
Jogger_2.setRun(run);
cout << endl << "Jogger Name: " << Jogger_2.getName() << endl <<
"walked " << Jogger_2.getWalk() << "miles, " << endl <<
"jogged " << Jogger_2.getJog() << "miles, and " << endl <<
"ran " << Jogger_2.getRun() << "miles." << endl;
return 0;
}
|
H File
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <iostream>
#include <string>
using namespace std;
#ifndef JOGGER_H
#define JOGGER_H
class Jogger {
public:
Jogger();
Jogger(string, int);
~Jogger();
string getName() const;
int getWalk() const;
int getJog() const;
int getRun() const;
void setName(string);
void setWalk(int);
void setJog(int);
void setRun(int);
private:
string newName;
int newWalk;
int newRun;
int newJog;
};
#endif
|
Second CPP (this is where I'm getting errors)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include "Jogger.h"
Jogger::Jogger() {
newWalk = 0;
newRun = 0;
newJog = 0;
}
Jogger::Jogger(string name, int walk, int jog, int run) {
newName = name;
newWalk = walk;
newJog = jog;
newRun = run;
}
Jogger::~Jogger() {
}
string Jogger::getName() const{
return newName;
}
int Jogger::getWalk() const{
return newWalk;
}
int Jogger::getJog() const{
return newJog;
}
int Jogger::getRun() const{
return newJog;
}
void Jogger::setName(string name) {
newName = name;
}
void Jogger::setWalk(int) {
newWalk = walk;
}
void Jogger::setJog(int) {
newJog = jog;
}
void Jogger::setRun(int) {
newRun = run;
}
|
Errors:
-Error 1 (Line 8) error C2511: 'Jogger::Jogger(std::string,int,int,int)' : overloaded member function not found in 'Jogger'
-Error 2 (Line 9) error C2597: illegal reference to non-static member 'Jogger::newName'
-Error 3 (Line 10) error C2597: illegal reference to non-static member 'Jogger::newWalk'
-Error 4 (Line 11) error C2597: illegal reference to non-static member 'Jogger::newJog'
-Error 5 (Line 12) error C2597: illegal reference to non-static member 'Jogger::newRun'
-Error 6 (Line 40) error C2065: 'walk' : undeclared identifier
-Error 7 (Line 44) error C2065: 'jog' : undeclared identifier
-Error 8 (line 48) error C2065: 'run' : undeclared identifier
-Error 9(Line 8) IntelliSense: no instance of overloaded function "Jogger::Jogger" matches the specified type
-Error 10 (Line 40) IntelliSense: identifier "walk" is undefined
-Error 11 (Line 44) IntelliSense: identifier "jog" is undefined
-Error 12 (Line 48) IntelliSense: identifier "run" is undefined