Hi Guys, I am having some problem with segmetation fault for like 10th times and again not able to solve it by myself. It drives me crazy I know, I am a dumb. Anyway, I am trying to create a Big Integer class for both examining OOP and it will be useful for Euler projects. I am having segmentation fault in line:
std::cout << *it << std::endl;
(in text editor Code tags were not working I do not know why. Maybe you are having the same problem.)
I need to know why this is happening. Actually, it will be good if I know how to handle segmentation fault and why it occurs. Thank you already.
There is nothing wrong with the code snippet. Post code where the problem can be reproduced. You may have an undefined behavior somewhere else (like out of bounds access).
if I construct num1 the fault occurs if I remove the line and run it does not. All the codes are these. So you say there is nothing wrong. Is it a linker issue then?
No, you clearly have omitted code. @coder777 says there is nothing wrong with the code that you showed - meaning, the problem is in the code you have not shown.
I can't see how a *it (a char) can be converted to a std::vector<int>. That code just doesn't make sense to me.
It seems to me that you're just changing code in a panic without thinking about your design. Just stop, remove all those members and implement one part at a time. I mean, why should a BigInt class have a string representation and a std:vector<int>?
Odd, that version is less than a year old. Still, it's clearly not working for you for some reason.
On Windows I recommend Visual Studio 2015 - the community edition is free. Make sure you choose to install all the C++ tools - the option for that is unticked by default.
There's also Code::Blocks, but I've never used it.
I wouldn't write the code like that myself, but I don't see anything there to cause a crash.
Do you have a debugger in your environment? If so, run the program in the debugger and let it crash. We can then example why it crashed in your environment.