Can't access the same Class data in different classes

I want to use the same airport class named 'air' which is defined in main() in different classes.
But I don't know why when I try to call the print function in class airport and thus call the print function in class runway, it failed to access the data in 'air'.

In this function of runway class, it can not get the 'n' data in 'air'.
How can I fix it?
1
2
void print(airport Airport){
      n=Airport.show();

1
2
3
int show(){
		return n;
	}


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


class airport{
	private:int n;string list[1000][3];
	public:
		class runway{
		private:
			int n;
			int no;
			string list[1000][3];
		public:
			runway(int id){
			no=id;
			}

		int showid(){
			return no; }

		void print(airport Airport){
			n=Airport.show();
			cout<<"The schedule of runway #"<<n<<": ";
			if(no==1){
				for(int i=0;i<n;i+=2){
					for(int k=0;k<3;k++){
					cout<<Airport.list[i][k];
					}
				}
			}
			else if(no==2){
				for(int i=1;i<n;i+=2){
					for(int k=0;k<3;k++){
					cout<<Airport.list[i][k];
					}
				}	
			}
		}

	};
	
	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;
		}


	int show(){
		return n;
	}

	void print(airport Airport){
		runway run1(1),run2(2);
		run1.print(Airport);
		run2.print(Airport);
	}

	};

		
		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;
}
it failed to access the data in 'air'.


Failed in what way? Error message, crash....

BTW. Is it really necessary the declare runway and flight inside the airport class?
I think it would be easier to declare them outside and inside the airport class you have member variables - called composition.
Have a look at this tutorial.
http://www.learncpp.com/cpp-tutorial/102-composition/
Topic archived. No new replies allowed.