expression must have class type

On line 34-37, there is error of "expression must have class type"

I have declare runway as member variables of airport, but I don't know why it can't recognise it.

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

class airport{
	private:
		int n;
		string list[1000][3];
		runway *run1,*run2;
		
	public:	
		airport(){
			run1 =new runway(1);
			run2 =new runway(2);
		}

	void store(int n1,int i,string no1,string type1,string planned_time1){
		n=n1;
		list[i][0]=no1;
		list[i][1]=type1;
		list[i][2]=planned_time1;
		}

	string assign(int no,int i,int j){
			return list[i][j];
	}


	int show(){
		return n;
	}

	void print(airport &Airport){
		run1.assign(Airport);
		run2.assign(Airport);
		run1.print;
		run2.print;
	}

	};
	
class runway{
		private:
			int n; //number of flights
			int no;
			int y;// number of rows in runway
			string list[1000][3];

		public:
			runway(int id){
			no=id;
			}


		void assign(airport &Airport){
			n=Airport.show();
			y=0;
			if(no==1)int i=0;
			else int i=1;
				for(int i;i<n;i+=2){
					for(int k=0;k<3;k++){
						list[y][k]=Airport.assign(no,i,k); 
					}
					y++;
				}
		}

		void print(){
			cout<<"\nThe schedule of runway #"<<no<<": \n";
			for(int i=0;i<y-1;i++){
				for(int k=0;k<3;k++){
					cout<<list[i][k]<<"\t";
				}
			}
		}
	};
	
	class flight{
		private:int n;string no,type,planned_time;
		public:
			flight(int n1,string no1,string type1,string planned_time1){
			n=n1;
			no=no1;
			type=type1;
			planned_time=planned_time1;
			}

			void assign(airport &Airport,int i){
			    Airport.store(n,i,no,type,planned_time);
			}
	};


int main(){
	int n;
	string no,type,planned_time;
	airport air;
	cout<<"Please input the number of flights in the timetable:\n";
			cin>>n;
			cout<<"Please input the detail of the flights:\n";
			for(int i=0;i<n;i++){
				cin>>no>>type>>planned_time;
				flight setup(n,no,type,planned_time);
				setup.assign(air,i);
			}
			air.print(air);

	return 0;
}
Hi,

Use the -> operator rather than the dot operator.

-> is called the pointer to member operator.

Some other errors:

9:3: error: 'runway' does not name a type
In constructor 'airport::airport()':
13:4: error: 'run1' was not declared in this scope
13:14: error: expected type-specifier before 'runway'
14:4: error: 'run2' was not declared in this scope
14:14: error: expected type-specifier before 'runway'
At global scope:
24:20: warning: unused parameter 'no' [-Wunused-parameter]
In member function 'void airport::print(airport&)':
34:3: error: 'run1' was not declared in this scope
35:3: error: 'run2' was not declared in this scope
In member function 'void runway::assign(airport&)':
58:17: warning: unused variable 'i' [-Wunused-variable]
59:13: warning: unused variable 'i' [-Wunused-variable]


To use runway, you must include it's header file or put it's class definition first. Better to have a separate header file - i like .hpp because it says a header file with cpp code inside. Also put the code for each class function in it's own cpp file. Name the files exactly after the class name.

You be able to get your IDE to do this stuff for you: create a new class, add new class functions. These make the right files, and provide function stubs in the cpp file.
It's really helpful, I have bee tortured by this for the whole day. I tried to use function prototype and place the airport::print under the definition of runway and now it works properly. Once again, I really appreciate your kind help!
Hi,

Are you going to consider having the separate header and cpp files like I mentioned? Then you won't have these issues.

You may have solved the issue in the simplest manner, but it bugs me that others often prefer this to actually doing things properly. It's well worth remembering that just because code works, doesn't mean that it is right.

Any way Good Luck :+)

Regards
Topic archived. No new replies allowed.