[prog] This segmetation fault makes no sence to me.
Sue Stones
suzo at bigpond.net.au
Sat May 31 20:56:49 EST 2003
On Sat, 31 May 2003 05:34, Jimen Ching wrote:
> On Fri, 30 May 2003, Sue Stones wrote:
> >anual salary is 350000
>
> Is this a software engineer's salary? ;-)
Yes but note it doesn't say what the currency is!
$US 1.00 = 118.350 JPY (Japan Yen)
$US 1.00 = 1,637.86 ITL (Italy Lire)
$US 1.00 = 8,254.38 IDR (Indonesia Rupiahs)
:-)
<cut>
> The same goes for andCo. Note also, I didn't see an assignment operator
> defined below, so one is generated for you. And it just does a byte by
> byte copy. I'll mention why this is significant later.
<cut>
I do have one written, I just didn't copy it here because I didn't think it
was relevent. (wrongly).
> Does Manager inheret from Employee? If so, you need a mem-initializer
> like so:
<cut>
Yes it does. I had thought that the mem-initialiser and calling the
constuctor of the base class were the same thing. I have re-erad that
section of the book and I understand it now. Thanks. (Now I just have to
remember it!)
<cut>
> The output looks like andCo.add() succeeded and returned. When 'return 0'
> is executed, the destructor comes into play. This is most likely where it
> segfaulted. As I mentioned above, an assignment operator function was
> probably generated (if you didn't define one). This will perform a byte
> copy of the contents of Manager.
Yes. When I ran the debugger it showed that the destructor for Employee is
called as soon as a Manager has been created. But fixing these things
dosen't solve the problem. If fact I can still use the derived class fine up
untill the end of the program.
>If Manager inherets from Employee and
> Employee has a 'char *' data member, then 'smith' is probably pointing to
> freed memory, since the temporary used in
>
<cut>
This seems to be the one mistake I didn't make.
> This is just a guess, since I don't know the class definition of Manager
> nor it's destructor definition. But the segfault is most likely due to
> some memory de-allocation problem.
>
> With gdb, if you compiled all of the code with -g3 -O0 (enable debugging
> with macro symbol and disable optimization), then you can put a break
> point in the destructor and walk through it. I.e.
<cut>
Yes I agree, but I still haven't found it!!!
Thanks for the instructions for gdb, it has helped a lot. I will try and
figgure out Kdevelop very soon now. (I didn't know what it was for untill
Meredydd mentioned it.)
> P.S. I just looked at the main function again, and I noticed 'smith' is a
> local variable. Are you sure you want to add a variable on the stack to
> some container in andCo? That doesn't look right. This could also be the
> problem. I recommend going through the process of running gdb to
> determine the cause of the segfault. This will tell you both the cause of
> the segfault and give you experience with using gdb.
Ah yes annother confusion set straight in my brain. Who knows what language
I was reverting to there! I had to look this up in the text book too!
Thanks for your help. It hasn't solved the problem whit that program, but I
have learnt a lot. Since I can still continue to write the program, (which
doesn't fit with my analysis of where the problem stems from) I will possibly
just do that and try and come back to the SEG Fault later.
sue
More information about the Programming
mailing list