View Single Post
Grep is offline
May23-11, 02:28 AM
P: 296
Quote Quote by JOZ View Post
I got this function from my lecturer but when i try to use it like this is gets "error: invalid conversion from 'void*' to 'Shape*'" is this because the lst_next function is a void? but in the list.c file that i got its full of voids that return something? which i thaught is weird but i got them from the lecturer...
Making lst_next return Shape* is probably just fine. Since you will only ever be interested in Shape* types, it's best to be specific with the type.

void* isn't quite what you'd think at first glance. It basically means a pointer to "something" that isn't specified. You can cast a void* to a specific type, since there's not much you can do with whatever the void* points to unless you have a type.

So void* is quite different from just void in the sense that void means nothing, whereas void* is a pointer to something not specified.

A quick comment on lines such as this:

else if(key==('B'))

The parentheses around 'B' are quite unnecessary, and just clutter it up and make it harder to read. Also, the parentheses around the expression in the if statement make it look too much like a function. This is perhaps a matter of opinion, but I would format functions like this:


But I would put a space after any statement that is followed by a parenthesized expression. I also tend to like to space out expressions a bit so things don't end up as a solid chunk of characters. Readability is very important. So in short, I suggest you format that line like this:

else if (key == 'B')

If nothing else, however, don't put the parentheses around 'B'.

Lastly, please wrap your code in code tags so it will be formatted better. It's hard to read like that, and you lose your indentation. Just put [ code] at the start and [ /code] at the end of your block of code, removing the spaces I put in after the square bracket (which I added so the forum software won't think it's a real tag).