I posted this in the beginner forums and nobody had an answer. I am getting an 'horse' class type redefintion error on line 10 of horse.cpp Not sure how its getting defined twice, Please Help!
#ifndef HORSE_H
#define HORSE_H
#include <iostream>
usingnamespace std;
// use header to declare horse class,
class Horse
{
private:
string name;
string rider;
int maxRunningDistPerSecond;
int distanceTraveled;
int racesWon;
public:
void setName(string);
void setRider(string);
int getMaxRunningDistPerSecond() const;
int getDistanceTraveled() const;
int getRacesWon() const;
};
#endif
#include <iostream>
#include "Horse.h"
usingnamespace std;
// define horse class with all information to be stored
class Horse
{
private:
string name;
string rider;
int maxRunningDistPerSecond;
int distanceTraveled;
int racesWon;
public:
void setName(string input)
{
name = input;
}
void setRider(string input)
{
rider = input;
}
int getMaxRunningDistPerSecond() const;
int getDistanceTraveled() const;
int getRacesWon() const;
};
//#include "stdafx.h"
// A Horse racing simulation program
#include <iostream>
#include <string>
#include "Horse.h"
usingnamespace std;
int main()
{
int numHorses = 0;
Horse horseArr[20] {};
// determine number of horses in race
cout << "How many horses are in the race?";
cin >> numHorses;
while (numHorses < 1 || numHorses > 20)
{
cout << "Please enter valid number of Horses";
cin >> numHorses;
}
// create Class array for numHorses and get fill in horse and rider names
for (int i = 0; i < numHorses - 1; i++)
{
cout << "Please enter the name of Horse " << i+1 << " : ";
string input;
getline(cin, input);
horseArr[i].setName(input);
cout << "Please enter the name of Rider for Horse " << i + 1 << " : ";
getline(cin, input);
Horse setRider(string input);
}
You've defined the Horse class in both files. I would say by the look of it you need to scrap the cpp file and re-write it as an implementation file. The header only holds the headings, the implementation cpp file has the nuts and bolts.