xcode 预期标识符或 '(' 在 '.' 标记之前
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3881078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Expected identifier or '(' before '.' token
提问by Zachary Markham
I'm new to Objective-C so I'm using a book to get to grips with it. I'm at a bit where it's explaining structs and I can't for the life of me get them to work.
我是 Objective-C 的新手,所以我正在使用一本书来掌握它。我有点在解释结构,我一生都无法让它们工作。
I have the following code:
我有以下代码:
int main (int argc, char *argv[])
{
struct node
{
int nodeID;
int x;
int y;
BOOL isActive;
};
typedef struct node myNode;
myNode.nodeID = 1;
}
and I'm getting the error written in the title. Every time I search for this error online I found different variations such as 'before '>' token' or 'before '}' token' but i can't find anything with the '.' token and it's really frustrating and I assume it's somethings ridiculously trivial and basic. Any help would be appreciated.
我收到了标题中写的错误。每次我在网上搜索此错误时,我都会发现不同的变体,例如“before '>' token”或“before '}' token”,但我找不到任何带有 '.' 的内容。令牌,这真的很令人沮丧,我认为这是非常琐碎和基本的事情。任何帮助,将不胜感激。
采纳答案by Zachary Markham
I've got it sorted now, I used the following and it seems to be fixed now:
我现在已经整理好了,我使用了以下内容,现在似乎已修复:
int main (int argc, char *argv[])
{
struct node
{
int nodeID;
int x;
int y;
BOOL isActive;
};
struct node myNode;
myNode.nodeID = 1;
myNode.x = 100;
myNode.y = 200;
myNode.isActive = TRUE;
}
Thanks for all your help Darth! :)
感谢您对达斯的所有帮助!:)
回答by
I believe you're trying to modify the actual type itself. nodeA
is now the type of that struct, much like int
. You need to do something like nodeA myNode
, then you would be able to perform myNode.nodeID = 1
without error.
我相信您正在尝试修改实际类型本身。nodeA
现在是该结构的类型,很像int
. 你需要做一些类似的事情nodeA myNode
,然后你就可以毫无错误地执行myNode.nodeID = 1
。
回答by RAX
I think the problem with the original code was, it was trying to make myNode a type name using typedef. Thus, myNode is NOT a variable that assignment can happen to. Rather, it was another alias for struct node.
我认为原始代码的问题是,它试图使用 typedef 使 myNode 成为类型名称。因此, myNode 不是一个可以赋值的变量。相反,它是 struct node 的另一个别名。