数据结构和算法 - 用C++写多项式相加算法,运行出现问题,求解
黄舟
黄舟 2017-04-17 13:00:30
0
1
632
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
Ty80

So you came to SegmentFault for help when you encountered SegmentFault?

It is actually normal for novices to encounter segfault, and they can be good at using GDB at this time. Use GDB to run your code and use the bt command to print the call stack:

#0  0x0000000000400f5a in Term::insertTerm (this=0x0, c=1, e=2) at tmp.cpp:24
#1  0x0000000000400db9 in addPlus (L=@0x7fffffffdf48: 0x603010, 
    M=@0x7fffffffdf50: 0x6030c0) at tmp.cpp:111
#2  0x0000000000400aa6 in main () at tmp.cpp:42

You can find that the initial N in the addPlus function is NULL, and if you directly call the N method, this will be NULL. deference A null pointer will naturally cause a segfault.

As for how to solve it, you should be able to figure it out yourself.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template