c2011 class type redefinition

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!

Horse.h
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


#ifndef HORSE_H
#define HORSE_H

#include <iostream>
using namespace 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 


Horse.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

#include <iostream>
#include "Horse.h"


using namespace 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;


};


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
39
40
//#include "stdafx.h"

// A Horse racing simulation program
#include <iostream>
#include <string>
#include "Horse.h"


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


	}
closed account (48T7M4Gy)
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.

http://www.cplusplus.com/forum/articles/10627/
Last edited on
Topic archived. No new replies allowed.