pointer error

Pages: 12
Nov 28, 2012 at 7:43pm
what about
1
2
3
4
5
6
7
8
int IntSLList::length(){
int len (IntSLList *ptr)

    if (*ptr!=0)
    return len(*ptr->next)+1;

    return 0;
}


i got error here says that expect initialization before if!
Nov 28, 2012 at 7:49pm
Well is ptr initialized anywhere? You didn't post the calling code. I also think you're getting confused with pointer notation.

return len(*ptr->next)+1;

This means nothing unless ptr is a pointer to a pointer, which it isn't.

if (*ptr!=0)

Are you checking to see if the pointer is not null? Get rid of the asterisk. Right now you're checking to see if the value pointed at by ptr is not 0.
Nov 28, 2012 at 8:01pm
but i have no other choices to finds the length of a linked list
recursively other than this cuz we wont be able to use more variables unless we need it.

*ptr is already initialized in the class itself
Nov 28, 2012 at 8:02pm
Oh, you're missing the starting bracket for your function.

And what I said about pointer notation still stands.
Nov 28, 2012 at 8:05pm
even if i took out the pointer and change the variable i get the same error> I hate errors that i dont understand i wont be able to fix it!!!!!!
Nov 28, 2012 at 8:08pm
I told you what the problem was, you're missing your opening bracket for your function.
Nov 28, 2012 at 8:17pm
its not about the bracket cuz still m having the same error
Nov 28, 2012 at 8:19pm
1
2
int IntSLList::length(){
int len (IntSLList *ptr)


Does this look weird to you? You're defining a function inside of another function.
Nov 28, 2012 at 8:30pm
oh thanku
Topic archived. No new replies allowed.
Pages: 12