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
#include <iostream>
#include <string>
usingnamespace 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;
}
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.
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