Cardona Jeison
Cardona Jeison

Reputation: 77

C++ help a warning with pointers

i need return the name of object, the pointer cabezera pointing to the object, but when run in the console print a warning Segmentation fault.

cancion *cola;
cancion *cabezera = new cancion("ca","name","cab","cab","cab","cab","cab",*cola,*cabezera);
cola = new cancion("cola", "cola", "cola", "cola", "cola", "cola", "cola", *cabezera, *cola);


cancion *tmp1 = new cancion ("1","1","1","1","1","1","1",*cabezera, *cola); 
cancion *tmp = new cancion ("1","1","1","1","1","1","1",*cabezera, *cola);
string entrega = "";
tmp1 = cabezera;
entrega = tmp1->getID(); //getID() return a string.
cout<<entrega<<endl;

Upvotes: 0

Views: 38

Answers (1)

IllusiveBrian
IllusiveBrian

Reputation: 3214

cancion *cabezera = new cancion("ca","name","cab","cab","cab","cab","cab",*cola,*cabezera);

Without knowing what the constructor actually looks like, in this case you are trying to dereference cola, which has not been assigned a value, and thus will give you a segmentation fault (technically undefined behavior, but >99% of the time a segmentation fault).

Upvotes: 3

Related Questions