CODE: http://pastebin.com/d685a1173
I can't seem to figure out why head==NULL is never true (line 58) and why line 74 produces a seg. fault...
thanks in advance for any help...
This is a discussion on Linked List & Seg Fault within the C++ Programming forums, part of the General Programming Boards category; CODE: http://pastebin.com/d685a1173 I can't seem to figure out why head==NULL is never true (line 58) and why line 74 produces ...
CODE: http://pastebin.com/d685a1173
I can't seem to figure out why head==NULL is never true (line 58) and why line 74 produces a seg. fault...
thanks in advance for any help...
The member "head" is never initialized in poly2 and thus causes a seg fault.
The int coeff, int expon) constructor never initializes the members; only the default constructor does.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
Is there anyway I can make the default constructor initialize the members for all the overloaded functions?
You need to fix the other constructor instead.Is there anyway I can make the default constructor initialize the members for all the overloaded functions?
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
I fixed it as follows: http://pastebin.com/d3542c5db
What's the main thing I am doing wrong?
You didn't fix it.
Member "head" is still never initialized in the int, int constructor.
Try applying a little logic to the problem.
What are you expecting will happen?
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
To begin with, the correct way to initialise the member variables in the default constructor is by using an initialisation list:
Now, in your constructor that takes two int arguments, head must surely be either NULL or uninitialised, so I am not sure why you check if head is equal to NULL. You can still initialise head to NULL using the initialisation list if you want, but there is no need to check if it is NULL.Code:polyType::polyType() : head(NULL), currNode(NULL), currPtr(NULL) {}
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way