help with Array in OOP (object)

well my homework is that, in a park of atraction (like disneyland) i read 2 things, m (quantity of atractions n (quantity of popular atractions) and so, obviously that first organize the array but i want test if the array is keep the atraction fine because the atractions hae 2 atributes ; a string (their name) and integer x (its level o fun) and the array organize for level high fun , and the problem is that the moment of run, show me Segmentation fault, and I don't know why

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

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

class atraccion {
	private:
	int x;
	string name;
	public:
	
	atraccion () {} 
	atraccion (int var, string nnombre){
		x=var;
		name = nnombre;
	}
	~atraccion() {}
	
	void set_x (int val) { 				//modifica el x
		x = val;
	}
	
	int get_x () {						//devuelve el x
		return x;
	}
	
	void set_name ( string nom) {			//modifica el nombre
		name =nom;
	}
	
	string get_name () {					//devuelve el nombre
		return name;
	}
};



int main (){
	int m, n, h,div;
	string nombre;
	atraccion ar [m];				//arreglo que almacena cada atraccion 
	
	cin>>m>>n>>h;
	
	if (m>= 1 && m<=100000) {
		for (int i=0;i<=m;i++) {
			cin>>nombre;
			cin>>div;
			ar[i].set_name(nombre);
			ar[i].set_x (div);
		}
		for (int j=0;j<=n;j++) {
			cout<<ar[j].get_name()<<endl;
		}
		
		
	}else{
		return 0;
		}
	
	return 0;
}
Last edited on
Line 41 is illegal. You have some compiler-specific functionality enabled that probably shouldn't be. Were it legal, m has an indeterminate value, so m could be anything including a negative number.

Give your variables values before you use them.
Last edited on
thank you, sorry, I believed that was like the array where might a value M or N and value M or N I don't know who is, but in OOP I see that these no is equal, sorry for my english,.

and in my home work tell 1<=M<=100000, for that I suposed that my array might are M , now I correct for 100000 and delete the first

thank you @cire
Last edited on
Topic archived. No new replies allowed.