xcode 错误“在非结构或联合体中请求成员‘selectedCountry’”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1168422/
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
What does error "request for member 'selectedCountry' in something not a structure or union" mean?
提问by user134721
My code is: dvController.selectedCountry = selectedCountry;
我的代码是: dvController.selectedCountry = selectedCountry;
Why do I get the error "request for member 'selectedCountry' in something not a structure or union"?
为什么我会收到错误消息“在非结构或联合体中请求成员‘selectedCountry’”?
回答by pix0r
You are probably trying to access a property "selectedCountry" on an object, and you forgot to include that header file. (At least that's what I usually do wrong when I get this error.)
您可能正在尝试访问对象上的属性“selectedCountry”,而您忘记包含该头文件。(至少这是我在收到此错误时通常会做的错误。)
回答by Jonathan Leffler
I suspect that dvController
is a pointer (to a structure) and not the structure. You need to use '->
' instead of '.
', perhaps.
我怀疑这dvController
是一个指针(指向结构)而不是结构。也许您需要使用“ ->
”而不是“ .
”。
回答by TahoeWolverine
I believe that I have encountered this problem when I have a member or variable that hasn't properly been initialized. Check to make sure that each of your objects has memory and is initialized properly.
我相信当我有一个没有正确初始化的成员或变量时,我遇到了这个问题。检查以确保每个对象都有内存并正确初始化。
Also, your question isn't as clear as it could be since there is the local variable selectedCountry and the member. Which one is being referred to here? I would assume the member, if the variable is actually a member of whatever is "self" that might be your problem. Whenever I program, I make sure to make distinctions between locals, members of the current class, and members of other classes so that it's easy to see what's going on when bugs come up. Just a thought.
此外,您的问题并不像它可能的那么清楚,因为有局部变量 selectedCountry 和成员。这里指的是哪一个?我会假设该成员,如果变量实际上是任何可能是您的问题的“自我”的成员。每当我编程时,我都会确保区分本地人、当前类的成员和其他类的成员,以便在出现错误时很容易看到发生了什么。只是一个想法。
回答by Clint
I just got this issue!
我刚遇到这个问题!
What was doing it in my case, was that I was attempting to access a property on an object of a different type!
在我的情况下,我试图访问不同类型对象的属性!
It hadn't moaned about alloc'ing and init'ing the object with a different type, but it sure as hell moaned about the property!
它没有抱怨分配和初始化具有不同类型的对象,但它肯定抱怨属性!
回答by ennuikiller
also if the types are NOT the same you can get this message. Casting to the right type usually resolves this.
此外,如果类型不同,您会收到此消息。转换为正确的类型通常可以解决这个问题。