please help, dont understand error

So I'm working on a school project and i have a couple classes.
In one of my classes, lets call it "RedLine" im instantiating a different class called "Passangers" using the following lines

Passangers *pass; (this line is in the private section)

pass = new Passangers; (this line is in my default constructor)

it works completly fine. However, i have another class called "BlueLine" and im attempting to do literally the exact same thing since that class also uses methods from Passangers, and im doing the exact same declaration.

Passangers *pass; (in private)

pass = new Passangers; (default construrctor scetion)

Now, the compiler is throwing me an error saying nonsense like undeclared identifier, missing type specifier - int assumed, etc etc

This is extremely wierd cuz why would it work in one class but not the other? Any help would be appreciated.
Usually when the compiler says "missing type specifier", it means that you forgot to specify the type in your initialization or declaration. It assumes you want an integer, which you probably don't, and then throws you insane errors because you're using an integer in a way that's not intended to be used.

Can we see some of your code? I can point out where your error line is and guide you to fixing it.

Oh, and don't forget to use <>code<> tags when pasting code so it's easy to read.
Last edited on
yeah sure, im going to post all 3 classes here for you.

Here is the RedLine class, which works with the passanger class

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#ifndef _RedLine_h_
#define _RedLine_h_


#include "Passangers.h"
#include "Times.h"
#include "BlueLine.h"

struct RedNode{

	string redStops;
	RedNode *next;
	RedNode *before;


};

class RedLine{

	
	RedNode *Head;
	RedNode *Tail;
    string RedStopNames[7];
	static const int carCapacity = 192;
	int carLoad;
	Passangers *passanger;
	BlueLine *blueTrain;
	Times *times;
	
	

	 RedNode* find(int pos) //function to find a specific node in the list
	{
		RedNode *temp = Head;
		for (int i=1; i<pos; i++)
		{
			temp = temp ->next;
		}
		return temp;
	}




public:

	RedLine(){
	   times = new Times;
		blueTrain = new BlueLine;
		Head = NULL;
		Tail = NULL;
		RedStopNames[0] = "A1"; 
		RedStopNames[1] = "A2"; 
		RedStopNames[2] = "A3"; 
		RedStopNames[3] = "A4"; 
		RedStopNames[4] = "B3"; 
		RedStopNames[5] = "B4"; 
		RedStopNames[6] = "B5"; 
		passanger = new Passangers;
		carLoad = 0;
		
		
	}
	


	void ConnectRedLine(){
		
		int i=1;
		
		while (i<8)
		{
		RedNode *curr = new RedNode;
        curr->redStops = RedStopNames[i-1];
		
		  if (i>=2)
		{
			
			RedNode *prev = find(i-1);
			
			prev->next = curr;
			curr->before = prev;
			curr->next = NULL;
			
			i++;

		}
		
		
		if(i==1)
		{
		curr->next = Head;
		Head=curr;
		
		i++;
		}
		


     }
	}
	
      
	
	
	void redTrain() 
	{
		RedNode *RedTrain = Head;
		RedNode *currStop = Head;
	    int totalPeopleA = 0;
		int totalPeopleB = 0;
		int x=0;
		int firstTime = 1;
		
		blueTrain->ConnectBlueLine();
	

		while(times->SystemOn)
		{

			
			totalPeopleA = times->MinutePassedA() + totalPeopleA;
			totalPeopleB = times->MinutePassedB() + totalPeopleB;
			
			blueTrain->blueTrain(totalPeopleA, totalPeopleB, firstTime);
			
			
			
			
			if(currStop->redStops == "A1" || currStop->redStops == "B5")
			{
				carLoad = 0;
			}

		
			
			if(currStop->redStops == "A1" ||currStop->redStops == "A2"||currStop->redStops == "A3"||currStop->redStops == "A4"
				||currStop->redStops == "A5")
			{

			
				if(carLoad <carCapacity)
				{

				carLoad = passanger->boardPassangerA(totalPeopleA, carLoad);
				}
			}

			if(currStop->redStops == "B1" ||currStop->redStops == "B2"||currStop->redStops == "B3"
				||currStop->redStops == "B4"||currStop->redStops == "B5")
			{
				
				carLoad = passanger->disembarkPassangerA(carLoad);
				if(carLoad <carCapacity)
				{
					
				carLoad = passanger->boardPassangerB(totalPeopleB, carLoad);
				}
			}

				
			
			if(RedTrain->next != NULL)
			{
			RedTrain = RedTrain->next;
			currStop = RedTrain;
		   
			x++;
			}
			
			if(x==6)
			{
				x--;
				continue;
			}

			if(RedTrain->next == NULL)
			{
				
				x=0;
				currStop = currStop->before;
							if(currStop->redStops == "A1")
				{
					RedTrain = currStop;
				}

			}
			
		
			
			

		}

	}
	


	  	~RedLine(){
		RedNode *curr = Head;
		RedNode *temp = NULL;
		while (curr != NULL)
		{
			temp = curr->next;
			delete curr;
			curr = temp;
		}
		//delete curr;
	}


};






#endif 


Now, here is the BlueLine class, which is currently not working with the passanger class.

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#ifndef _BlueLine_h_
#define _BlueLine_h_



#include "Passangers.h"



struct BlueNode{

	string blueStops;
	BlueNode *next;
	BlueNode *before;


};



class BlueLine{

public:
	
	BlueNode *currStop;
	BlueNode *BlueTrain;
	BlueNode *Head;
	BlueNode *Tail;
    string BlueStopNames[4];
	static const int carCapacity = 192;
	int carLoad;
	int x;
	Passangers *passanger;
	
	
	
	

	 BlueNode* find(int pos) //function to find a specific node in the list
	{
		BlueNode *temp = Head;
		for (int i=1; i<pos; i++)
		{
			temp = temp ->next;
		}
		return temp;
	}





	BlueLine(){
		
		passanger = new Passanger;
		Head = NULL;
		Tail = NULL;
		BlueStopNames[0] = "A5"; 
		BlueStopNames[1] = "B3"; 
		BlueStopNames[2] = "B2"; 
		BlueStopNames[3] = "B1"; 
		
		carLoad = 0;
		currStop=Head;
		BlueTrain=Head;
		x=0;
		
		
	}
	


	void ConnectBlueLine(){
		int i=1;
		
		while (i<5)
		{
		BlueNode *curr = new BlueNode;
        curr->blueStops = BlueStopNames[i-1];
		
		  if (i>=2)
		{
			
			BlueNode *prev = find(i-1);
			
			prev->next = curr;
			curr->before = prev;
			curr->next = NULL;
			
			i++;

		}
		
		
		if(i==1)
		{
		curr->next = Head;
		Head=curr;
		
		i++;
		}
		


     }
	}
	
      
	
	
	int blueTrain(int &totalPeopleA, int &totalPeopleB, int &firstTime) 
	{


		if(firstTime == 1)
		{
		currStop = Head;
		BlueTrain = Head;
		x=0;
		firstTime = firstTime +1;


		}
	
								
			
			if(currStop->blueStops == "A5" || currStop->blueStops == "B1")
			{
				carLoad = 0;
			}

		
			
			if(currStop->blueStops == "A5")
			{

			
				if(carLoad <carCapacity)
				{

					carLoad = passanger->boardPassangerA(totalPeopleA, carLoad);
				}
			}

			if(currStop->blueStops == "B1" ||currStop->blueStops == "B2"||currStop->blueStops == "B3")
			{
				
				carLoad = passanger->disembarkPassangerA(carLoad);
				if(carLoad <carCapacity)
				{
					
				carLoad = passanger->boardPassangerB(totalPeopleB, carLoad);
				}
			}

				
			
			if(BlueTrain->next != NULL)
			{
			BlueTrain = BlueTrain->next;
			currStop = BlueTrain;
		   
			x++;
			}
			
			if(x==3)
			{
				x--;
			    return 0;
			}

			if(BlueTrain->next == NULL)
			{
				
				x=0;
				currStop = currStop->before;
							if(currStop->blueStops == "A5")
				{
					BlueTrain = currStop;
				}


			}
			
		return 0;

			

		

	}
	
	
	
	




	  	~BlueLine(){
		BlueNode *curr = Head;
		BlueNode *temp = NULL;
		while (curr != NULL)
		{
			temp = curr->next;
			delete curr;
			curr = temp;
		}
		//delete curr;
	}


};
#endif 



I read someplaces that a forward declaration would solve my problems, but I had just tried that and it didnt help at all.
also, here is the fully funcational passanger class as well.

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#ifndef _Passangers_h_
#define _Passangers_h_

#include <time.h>
#include "Times.h"
#include "RedLine.h"
#include "BlueLine.h"




class Passangers{
public:
	
	Properties *prop;
	string hourA;
	string hourB;
	char tempA[2];
	char tempB[2];
	int disHoursA;
	int disMinutesA;
	int disHoursB;
	int disMinutesB;
	int disHoursC;
	int disMinutesC;
	int disHoursD;
	int disMinutesD;
	string mykey;
	const char *proptempA;
	const char *proptempB;
	int numPropA;
	int numPropB;
	int totalPeopleA;
	int totalPeopleB;
	Times *dis;
	



	Passangers()
	{
		
	    dis = new Times; 
		  prop = Properties::getInstance();  
          prop->readPropertyFile("a3.prop");
		   totalPeopleA = 0;
		    totalPeopleB=0;
			disHoursA=6;
			disMinutesA=0;
			disHoursB=6;
			disMinutesB=0;
				disHoursC=6;
			disMinutesC=0;
				disHoursD=6;
			disMinutesD=0;
		  
	}


	int PassangersPerMinuteA(int hours)
	{
		
		int peoplePerMinuteA;
	

	   hourA = itoa(hours,tempA, 10);

		
		srand(time(NULL));
		 
		if(hours < 10){
        mykey = '0'+hourA+'.'+"passengers"+'.'+"volume"+'.'+'A'+' ';
		}
		else{
			mykey = hourA+'.'+"passengers"+'.'+"volume"+'.'+'A'+' ';
		}
		string propertyA = prop->getProperty(mykey);
		
		proptempA = propertyA.c_str();

		numPropA = atoi(proptempA);

			peoplePerMinuteA=rand() % numPropA;
			peoplePerMinuteA = (peoplePerMinuteA *5) *2;
	
		totalPeopleA = totalPeopleA + peoplePerMinuteA;

		return totalPeopleA;
		
		}

	int PassangersPerMinuteB(int hours)
	{
		
		
	int peoplePerMinuteB;
	
		

	   hourB = itoa(hours,tempB, 10);

		
		srand(time(NULL));
		 
		if(hours < 10){
        mykey = '0'+hourB+'.'+"passengers"+'.'+"volume"+'.'+'B'+' ';
		}
		else{
			mykey = hourB+'.'+"passengers"+'.'+"volume"+'.'+'B'+' ';
		}
		string propertyB = prop->getProperty(mykey);
		
		proptempB = propertyB.c_str();

		numPropB = atoi(proptempB);

		peoplePerMinuteB=rand() % numPropB;
		

		peoplePerMinuteB = (peoplePerMinuteB * 5) *2;
		totalPeopleB = totalPeopleB + peoplePerMinuteB;

		return totalPeopleB;
		
	}

	int boardPassangerA(int &totalPeopleA, int &carLoad)
	{
		

		carLoad = carLoad + totalPeopleA/5;
		totalPeopleA = totalPeopleA - totalPeopleA/5;
		return carLoad;
		
	}

	int boardPassangerB(int &totalPeopleB, int &carLoad)
	{
		carLoad = carLoad + totalPeopleB/5;
		totalPeopleB = totalPeopleB - totalPeopleB/5;
		return carLoad;

	}

	int disembarkPassangerA(int &carLoad)
	{


		
		if(disMinutesA == 60)
		{
			disHoursA = disHoursA +1;
			disMinutesA = 0;
		}
		
		 hourA = itoa(disHoursA,tempA, 10);

		
		
		 
		if(disHoursA < 10){
        mykey = '0'+hourA+'.'+"passengers"+'.'+"destination"+'.'+'B'+' ';
		}
		else{
			mykey = hourA+'.'+"passengers"+'.'+"destination"+'.'+'B'+' ';
		}
		string propertyA = prop->getProperty(mykey);
		
		proptempA = propertyA.c_str();

		numPropA = atoi(proptempA);
		
        double disembark = numPropA;

	    disembark = disembark/100.0;

		carLoad = carLoad - (carLoad * disembark);
		return carLoad;

		

	}

	

	


	~Passangers()
	{
	}


	
};


#endif 
You haven't provided "Times.h", but from the looks of it, you're trying to use a string type but the compiler can't resolve it.
That's because you're probably referring to the string from the std namespace.
Declare your strings with std::string /* name */ to resolve it.

Oh, and don't forget to do your copy constructor and copy-assignment operator overloads. Since you have a destructor, you probably need all three.
Refer to the rule of three here.
http://en.wikipedia.org/wiki/Rule_of_three_%28C%2B%2B_programming%29
Last edited on
here is the times class
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef _Times_h_
#define _Times_h_

#include "Passangers.h"


class Passangers;

class Times{
public:
	
	
	bool SystemOn;
	int timeBetweenStations;
	int TotalTravelTime;
	int hours;
	int minutes;
	int minutesB;
	int tempA;
	int tempB;
	int disHours;
	int disMinutes;
	Passangers *pass;



	Times(){
		pass = new Passangers;
		SystemOn=true;
		timeBetweenStations = 2;
		TotalTravelTime = 0;
		hours = 6;
		minutes = 0;
		minutesB= 0;
		tempA = 0;
		tempB = 0;
		
		disHours=6;
		disMinutes=0;
		
	}

	int MoveStation(){
		TotalTravelTime = TotalTravelTime + timeBetweenStations;
	//	printf("Total travel time is : %d\n", TotalTravelTime);
		return TotalTravelTime;
		
	}

	int MinutePassedA()
	{
		int TotalPeopleA;
		
		
		while(hours != 22){
			minutes = minutes + 2;
		
			   if(minutes == 60)
		   {
			   hours = hours +1;
			   minutes = 00;
		   }

			TotalPeopleA = pass->PassangersPerMinuteA(hours);
			tempA = tempA + TotalPeopleA;
		

		return tempA;
		

		
		}
	}
		int MinutePassedB() //change minutes to minutes B or something.
	{
		
		int TotalPeopleB;
		
		while(hours != 22){
			minutesB = minutesB + 2;
		
			   if(minutesB == 60)
		   {
			   hours = hours +1;
			   minutesB = 00;
		   }

	    disembarkMinutes(minutesB);
		disembarkHours(hours);
		TotalPeopleB = pass->PassangersPerMinuteB(hours);
		tempB = tempB + TotalPeopleB;

					if (hours == 22)
		{
			SystemOn=false;
		}
		
		return tempB;

		
		}
	}

		int disembarkMinutes(int minutes)
		{
			return minutes;

		}

		int disembarkHours(int hours)
		{
			return hours;
			
			
		}


	


	~Times(){
	}
};







#endif 


as far as the String thing goes, the string class is being predefined by a file my professor gave me, it looks like this.

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
53
54
55
56
57
58
59
60
61
62
#ifndef _Properties_h_
#define _Properties_h_


#include <fstream>
#include <iostream>
#include <map>
#include <string>
using namespace std;


// -----------------------------------------------------------------------------
// Properties
// ==========
// A useful object to hold all properties (from a property file, for example)
// for later access.
// Properties is implemented as a singleton so that clients don't need to
// have many (inefficient) instances.
// -----------------------------------------------------------------------------


typedef map <string, string, less< string > > kvpStore;


class Properties {


public:

        // Constructor is private, as this is a singleton.
                               ~Properties ();

	// Use "getInstance()" to get a reference to the singleton.
	static Properties     * getInstance();

	bool                    readPropertyFile (string fileName);
	bool                    addProperty (string key, string value);

		// Most clients just need to get a value based on a key. 
	string                  getProperty (string key);

private:

        // Constructor is private, as this is a singleton.
                                Properties ();

	// Data members
        static Properties     * instance;
        bool                    readFile;

	// members to support Standard Template Library map, if we choose
	// to use that instead of PropertyNode
	kvpStore                store;
	kvpStore :: iterator    iterator;


};


#endif



so, my other concern is....whats the difference between RedLine and BlueLine such that RedLine works and BlueLine doesnt? It makes absolutly no sense. When i provide a forward declaration...it throws me a diferent error saying no appropriate default constructor avialable.
also, these are the exact errors its throwing me
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
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\times.h(23): error C2143: syntax error : missing ';' before '*'
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\times.h(23): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\times.h(23): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\times.h(28): error C2065: 'pass' : undeclared identifier
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\times.h(28): error C2061: syntax error : identifier 'Passangers'
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\times.h(64): error C2065: 'pass' : undeclared identifier
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\times.h(64): error C2227: left of '->PassangersPerMinuteA' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\times.h(90): error C2065: 'pass' : undeclared identifier
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\times.h(90): error C2227: left of '->PassangersPerMinuteB' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\blueline.h(35): error C2143: syntax error : missing ';' before '*'
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\blueline.h(35): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\blueline.h(35): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\blueline.h(57): error C2065: 'passanger' : undeclared identifier
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\blueline.h(57): error C2061: syntax error : identifier 'Passangers'
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\blueline.h(143): error C2065: 'passanger' : undeclared identifier
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\blueline.h(143): error C2227: left of '->boardPassangerA' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\blueline.h(150): error C2065: 'passanger' : undeclared identifier
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\blueline.h(150): error C2227: left of '->disembarkPassangerA' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\blueline.h(154): error C2065: 'passanger' : undeclared identifier
1>c:\users\twiggy\desktop\mynewwork\code\assignmentthree\assignmentthree\blueline.h(154): error C2227: left of '->boardPassangerB' must point to class/struct/union/generic type
1>          type is ''unknown-type''
No appropriate default constructor available means just that: there's no proper constructor available for the type of declaration of the object for which you specified.

You don't seam to understand what you're doing here. This is why I wish professors didn't start teaching C++ before C, it's like teaching you to run before you crawl.

But before I get started on explaining on what the problem in your code is, let me ask what's your purpose with this code? It looks to me like you're trying to make some sort of primitive linked list. Is that right?
basicly its a train simulation, it simulates 2 train lines each going from point A to point B, back and forth, picking up and disembarking passangers. Each time a train moves a station, 2 minutes pass. Every minute , people enter the train stations equally distributed based on a file the prof gave us.

I just wanna point out that this was all working before. I simply changed something (dont remember what) and suddenly its not letting me instantiate classes in those 2 particular classes. Theres no reason in my mind of why it should work completly perfectly in both classes, then suddenly stop working in 1 of them. Makes no sense.
You're using a type before it's defined.
Assuming, in your main program, you include "Passangers.h", follow through with the includes.
Before you even declare and define class Passangers, you include "Times.h".
One of its members, within 'class Times' is a 'Passangers *pass' type. In other words, your 'class times' is trying to use a 'class Passangers' type before the type is even declared to exist. It's complaining, so you forward declared 'class Passangers' to shut it up. However, even if you forward-declared the class, it doesn't know that a default constructor exists for that class, because that hasn't been declared yet either, which is why it's complaining that it's not available.

One of our solutions is to first fully declare class Passangers type before class Times, and to forward-declare all of the functions within those classes.
Then, in their respective .cpp files, define those functions. That way, you'll resolve all definition and declaration-related complaints.

This is some poor code, though. I don't like your proffessor, if he wrote this I'd fire him.
what kind of details makes it poor. Im still newby so ill take any advice you can give...i understand ur solution, thanks for ur help im gonna try to do it. but the more specific critisizm u give me the better it is for me, if you dont mind.
Mind, that I'm just skimming through the code and not yet looking through the logic, but just pointing out obvious things.


Firstly and probably most importantly, the rule of three is not being followed.
I see a destructor but no copy-constructor and assignment operator overloads. When you're dealing with pointers and you don't have those, things get catastrophic because if you assign an object to another of the same type, the -pointers- will be copied but not the contents as they should (meaning the destructor will run its course twice for the same block of memory).
Which of course, lead to memory leaks or worse.

Next, I see a lot of preprocessor macros. Newbies shouldn't use those until they're very comfortable with them.

I see a lot of headers, one for each class (which is okay) but you always want to properly forward-declare classes, structures, and functions before using them within another class. Follow through with your includes. If you're using a type before you declare such a thing to exist, you're shooting yourself in the foot. In cases like yours, you want to fully declare the classes and forward-declare their methods in the header, and define those methods in their respective cpp files.
Note you don't have to include the cpp files, just the headers. The compiler's linker will look for a way to resolve the function symbols by looking through all the cpp files until it finds one.

You don't have global variables, which is good. Most newbies mess that up.
As for your project, I'd start it over from scratch.

Your trains are equivalent, yes? If you're using more than one train, you should only have just one class for that and simply declare two instances of the same type.
You also want to avoid using a namespace and instead use the scope resolution operator :: to resolve namespaces (i.e. std::cout << "This is how it's done!" << std::endl; ) because using a namespace is heavy in the sense that it imports all the functions from that namespace into the global namespace, which can cause problems when functions and/or types with the same-name conflict are used. If you're going to use something like a string from namespace and nothing else, you can optionally import just that like so: using std::string;
Use a manager to manage things and store what you -need- in the classes.

To go about your project, create a managment class that manages the trains (and optionally the passangers). I don't know the exact details of your project, so I can't tell you as to how to go about recording the necessary data.

One thing I can advise though is, if both your train and your passengers depend on some sort of time, use inheritance of some kind of time class so you don't have to reinvent the necessary methods to manage time for both of them.
Last edited on
Topic archived. No new replies allowed.