A weird error
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.
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.
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.
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
MikeD
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

MikeD
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
Plus it's just wrong
Worlds at War (Current Project) - http://www.awkward-games.com/forum/
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
.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
.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
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.
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.
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.
kalimba Wrote:Quote:And you should always use a forward declaration in the header, whenever possibleFixed your post.
Fixed your fixed up post.
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
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
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.

