Fun(object** p,int n) not calling child member function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void get_station(station **p,int n) {
	cout << p << endl;	
	for (int i=0;i<n;i++) {
		cout << "ADDRESS p[" <<i<<"] in #get_station# " << p[i] << endl;
		cout << "Station: ";
		//cout << "get_id() " << i+1 << "\n";
		p[i]->get_id();
		cout <<" is on positioni: ";
		p[i]->get_on();
		cout << "\n\n";
	}
}
int main() {
  cout << Array << endl;
  get_station(station::get_A(),n);
  for (int i=0;i<o;i++) {
	cout << "ADDRESS in main of p["<<i<<"] : " << Array[i] << endl;
	cout << "Station name through pointer: " << Array[i]->get_id()<<endl;
  }
  return 0;
}


In main it's working, but not when in function. Station is a parent class and A is static station**
Last edited on
What is exactly not working?
Also, I need more information on the variables (What is Array[]?, what does get_A() do?)
When i call p[i]->get_something(); inside "void get_station" nothing happens... I can't understand why. In main, the same code is working.

station** station::A=NULL;

A is a table containing the addresses of n objects which are children of station. I'm trying to get polymorphism work.

station** Array; inside main
station** get_A() {return A;}
Can you post the code that works?
(the one with everything in the main function)

I have a bad feeling about this line
 
get_station(station::get_A(),n);
Last edited on
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
int main() {
	float ptt;
	int o,s,n;
	station** Array;
	
	
	cout << "Sta8moi OIL: \n";
	cin >> o;
	cout <<"Sta8moi SUN: \n";
	cin >>s;
	
	oil *oil_p = new oil[o];
	sun *sun_p = new sun[s];
	Array = station::get_A();
	n = station::get_i();
	cout << Array << endl;
	get_station(station::get_A(),n);
	
	for (int i=0;i<o;i++) {
		cout << "ADDRESS sth main tou p["<<i<<"] : " << Array[i] << endl;
		cout << "Onoma sta8mou me pointer: " << Array[i]->get_id()<<endl;
	}
	
	cout << "Isxus pou apaitei h poli: \n";
	cin >> ptt;
	while (ptt>0) {
		alert(power(Array));
		
		cout << "Isxus pou apaitei h poli: \n";
		cin >> ptt;		
	}
	
	
	return 0;
}


n is the number of elements. The code runs but i get no results from the get_station
Last edited on
Are Array and A the same thing?
In your first code , you're not doing
Array = station::get_A();
yes they are the same, i added only a piece of main in the first code
Solved... it was just too stupid, the get_ funs returned int or char*... check the main code, they are inside cout...
^_^
Topic archived. No new replies allowed.