pointer error

Pages: 12
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!
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.
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
Oh, you're missing the starting bracket for your function.

And what I said about pointer notation still stands.
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!!!!!!
I told you what the problem was, you're missing your opening bracket for your function.
its not about the bracket cuz still m having the same error
1
2
int IntSLList::length(){
int len (IntSLList *ptr)


Does this look weird to you? You're defining a function inside of another function.
oh thanku
Topic archived. No new replies allowed.
Pages: 12