 |
 |
Please help with structures!
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status:
Offline
|
|
I'm programming in Objective C. This is in one of my header files that I made:
#ifndef windowVariables
#define windowVariables
unsigned int windowNumber = 0;
typedef struct
{
GameWindow *window;
BOOL shouldClose;
}saveInfo;
typedef struct
{
GameWindow *window;
void *next;
}windowListNode;
#endif
Later in my program I use malloc to make come windowListNodes. But when I try to make a saveInfo thing, first here is the code that I used:
saveInfo *info;
info = (saveInfo *)malloc(sizeof(saveInfo));
info->window = window;
info->shouldClose = shouldClose;
Now here is the error that I get when i try to compile it:
GameController.m: In function `-[GameController saveAs:shouldClose:]':
GameController.m:78: parse error before `*'
GameController.m:79: `info' undeclared (first use in this function)
GameController.m:79: (Each undeclared identifier is reported only once
GameController.m:79: for each function it appears in.)
The * that it is referring to is in the line saveInfo *info; What is my problem? I can't seem to figure this out and it looks like it should be so simple.
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
Hmmm... Are you declaring saveInfo the first thing in the block of code which it's in? If not, it'll generate that error like:
void function()
{
wee();
PXNumber *foo;
}
v |m|PXController.m (1 Error)
/_\ parse error before `*'
(like my ASCII representation of PB? :-)
If it's an int rather than a structure, it'll make a different error, but the idea's the same.
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status:
Offline
|
|
Ok, I figured out what the problem was. I can't believe that I missed it. Since I didn't put in the entire method where I called SaveInfo *info; you couldn't see it. The problem was that SaveInfo *info; wasn't at the beginning of the method. I forgot that Objective C requires you to define all of your local variables at the beginning of the method. I had something like x= 4; before SaveInfo *info; so the compiler didn't like that. This is what I get for taking a class in C++ the same time that I'm teaching myself Objective C. I spent so long trying to figure out what the problem was and it was so simple. It's always the simple things that I get stuck on.The long, subtle mistakes I catch right away. 
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Feb 2001
Location: Portland, OR, USA
Status:
Offline
|
|
Just a clarification. It isn't just at the beginning of methods, you can also declare variables at the beginnings of blocks like parallax mentioned. (Anywhere after a {, basically.)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status:
Offline
|
|
I never knew that you could declare a variable at the beginning of a block but it makes sense. Thanks.
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
Yup, like:
for (i=0; i < 10; i++)
{
int *i;
...
}
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|