0

我需要返回对象的名称,指针 cabezera 指向对象,但是在控制台中运行时会打印警告分段错误。

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

1 回答 1

3

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

在不知道构造函数实际上是什么样子的情况下,在这种情况下,您试图取消引用可乐,它没有被分配一个值,因此会给您一个分段错误(技术上未定义的行为,但 > 99% 的时间是分段错误)。

于 2013-11-10T04:03:27.977 回答