A weird error

Nibbie
Posts: 3
Joined: 2009.06
Post: #1
Hello,

I am getting a really odd error in my opinion. (I am new to objective-c)
I have googled it a lot, and to no anvil.

I created a new subclass of NSObject, and When I try to include another class ("#inport "This.h") I get errors. When I take off the inclusion, the errors go away.

The error I am getting is:
error: expected specifier-qualifier-list before 'SingletonGameState'.

And it points me to this line:
SingletonGameState *sharedState;

I am wondering what this error even means.

Thanks a ton. Ninja
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
Two things:
  • You've misspelled #import as #inport in your post. I hope it's not that way in your code...
  • When including a header in your code breaks the following line in the file including it, it usually means there's a syntax error toward the end of the header. Check for missing semicolons at the end of structs and other things in that category.
Quote this message in a reply
Member
Posts: 65
Joined: 2009.03
Post: #3
I've also had this error and found it to be because of circular references between classes. I've solved it by having @class This in the .h file and then doing the actual import of This.h in the .m file.

Not sure if your getting the error for the same reasons, but after a lot of mucking about that is what solved it for me Grin

MikeD
Quote this message in a reply
Moderator
Posts: 373
Joined: 2006.08
Post: #4
If you're really naming your class 'This', then that's a problem too, since 'this' is reserved. 'This' isn't reserved (since the 't' is capitalized), but it means that every time you miss the shift key and then compile, you're going to get some misleading errors.

Plus it's just wrong Rasp

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2009.06
Post: #5
He he he. Yes my classes are not named This, but now that I think about it that would be funny and mean. This, tHis, thIs Rasp .Circular errors I think is whats going on. Sorry for the long delay for answering. Thanks aton. Now I at least have a clue what is going on.
//time passed
I found the circle. Now I know what to do. Thanks
Quote this message in a reply
Moderator
Posts: 133
Joined: 2008.05
Post: #6
this is not a reserved keyword in Objective-C.

And you should always use a forward declaration in the header and do the actual import in the .m file. Will save you tons of compile time as your project grows larger.
Quote this message in a reply
Moderator
Posts: 373
Joined: 2006.08
Post: #7
ah, right, sry.

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Quote this message in a reply
Member
Posts: 34
Joined: 2009.01
Post: #8
longjumper Wrote:And you should always use a forward declaration in the header, when practical and appropriate, and do the actual import in the .m file. Will save you tons of compile time as your project grows larger.
Fixed your post.
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #9
kalimba Wrote:
Quote:And you should always use a forward declaration in the header, whenever possible
Fixed your post.

Fixed your fixed up post.
Quote this message in a reply
Member
Posts: 65
Joined: 2009.03
Post: #10
Hey guys, having read the last few posts, what is the best practices for using a forward declaration in .h and the import in .m

I'm only doing that at the moment if I hit a problem and my imports are getting a little complicated. How are you guys handling things when you have 20+ classes etc?

Cheers

MikeD
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #11
Forward declare when all you need is a class's symbol name (which tends to be most of the time in header files). Import when you need anything else that's defined by the header. Try to keep the number of imports to the minimum necessary.
Quote this message in a reply
Post Reply