search

Home  >  Q&A  >  body text

数据结构和算法 - 用C++写多项式相加算法,运行出现问题,求解

黄舟黄舟2803 days ago629

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 13:02:30

    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.

    reply
    0
  • Cancelreply