Class Type redefinition error

Getting Class Type redefinition error in class BikeRides { line in cpp.
I am not sure how I can create the Class in the source file after declaring it in the header.

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
52
  //Header
#ifndef _BikeRides_h_
#define _BikeRides_h_


#include <iostream>
#include <string>

#include <vector>
#include <array>

using std::cout;
using std::endl;
using std::string;


/**
* Route to a destination with one-way distance
*/
struct Route {
	string d_destination;
	float d_distance;
};

/**
* Ride by a rider on a route in a certian time (hours as float)
*/
struct Ride {
	string d_rider;
	Route d_route;
	float d_time;
};


class BikeRides {
protected:
	std::array<Route, 3> d_trainingRoutes{ { { "Trim Road", 25.0f },{ "Gatineau Park", 30.0f },{ "Pinhey Point",45.0f } } };
	std::vector<Ride> d_rides;
public:
	
	Ride* getLongestRide();
	
	bool getNRide(int nth, Ride& result);
	
	void addRide(const Ride& r);
	
	void print();
	
	int removeRides(const Route& r);
};
#endif



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

//cpp
#include <iostream>
#include <vector>

#include "bikerides.h"

class BikeRides {  //error here

	std::array<Route, 3> d_trainingRoutes{ { { "Trim Road", 25.0f },{ "Gatineau Park", 30.0f },{ "Pinhey Point",45.0f } } };
	std::vector<Ride> d_rides;

	Ride* getLongestRide() {
		
	}

	bool getNRide(int nth, Ride& result) {
		
	}


	void addRide(const Ride& r) {
		
	}

	void print() {
		
	}

	int removeRides(const Route& r) {
		
	}
};



I removed the extra details for better reading.
Last edited on
in your cpp file write the implementation for each method like the example below.

1
2
3
4
int BikeRides::removeRides(const Route& r)
{

}
@rafae11 thank you that works.

Topic archived. No new replies allowed.