从你发布的内容来看,一切看起来都很好。你能显示/确切地说/ ex_ptr的 定义是什么样的?无论ex_ptr是什么,似乎没有有一个与之相关的地址。如果它只是 " pointer'的错误类型,我已经预料到该消息会拼写出来。所以我的猜测是 ex_ptr实际上就像一个常数,就像那个奇怪的那样 听起来...... -leor - Leor Zolman --- BD软件--- www.bdsoft.com C / C ++,Java,Perl和Unix的现场培训 C ++用户:下载BD Software的免费STL错误消息解密器: www.bdsoft.com/tools/stlfilt.htmlFrom what you''ve posted, all looks fine. Can you show /exactly/ what thedefinition of ex_ptr looks like? Whatever ex_ptr is, it doesn''t seem tohave an address associated with it. If it were just the wrong type for"pointer", I''d have expected the message to spell that out. So my guess isthat "ex_ptr" is actually something like a constant, as weird as thatsounds...-leor--Leor Zolman --- BD Software --- www.bdsoft.comOn-Site Training in C/C++, Java, Perl and UnixC++ users: Download BD Software''s free STL Error Message Decryptor at: www.bdsoft.com/tools/stlfilt.html 你几乎肯定会误诊这个问题。在报告错误的行之前查看 行。简单的事情,比如 错过了'';''之前可能就是这样的罪魁祸首。请注意下面你的作业使用 ,这很好。 (如果你的使用不正确'/ b $'''extern'',那么可能会导致链接错误。 #include< stdio .h> struct example_struct { int f; } basestruct = {0 }; struct example_struct * ex_ptr =& basestruct; int main(无效) { struct example_struct **指针; 指针=& ex_ptr; (*指针) - > f = 3; printf(" basestruct.f =%d \ n",basestruct.f); printf(" ex_ptr-> f =%d \ n",ex_ptr-> f ); printf("(*指针) - > f =%d \ n",(*指针) - > f); 返回0 ; } basestruct.f = 3 ex_ptr-> f = 3 (*指针) - > f = 3You have almost certainly misdiagnosed the problem. Look to the linesbefore the one for which the error is reported. Simple things likemissing a '';'' on the line before may be such a culprit. Notice the useof your assignment below, which is fine. (If you had an incorrect useof ''extern'', that would probably lead to a linking error instead).#include <stdio.h>struct example_struct{int f;} basestruct = { 0};struct example_struct *ex_ptr = &basestruct;int main(void){struct example_struct **pointer;pointer = &ex_ptr;(*pointer)->f = 3;printf("basestruct.f = %d\n", basestruct.f);printf("ex_ptr->f = %d\n", ex_ptr->f);printf("(*pointer)->f = %d\n", (*pointer)->f);return 0;}basestruct.f = 3ex_ptr->f = 3(*pointer)->f = 3 你几乎肯定会误诊这个问题。在报告错误的行之前查看 行。简单的事情,比如 错过了'';''之前可能就是这样的罪魁祸首。请注意下面你的作业使用 ,这很好。 (如果你的使用不正确'/ b $'''extern'',那么可能会导致链接错误。 #include< stdio .h> struct example_struct { int f; } basestruct = {0 }; struct example_struct * ex_ptr =& basestruct; int main(无效) { struct example_struct **指针; 指针=& ex_ptr; (*指针) - > f = 3; printf(" basestruct.f =%d \ n",basestruct.f); printf(" ex_ptr-> f =%d \ n",ex_ptr-> f ); printf("(*指针) - > f =%d \ n",(*指针) - > f); 返回0 ; } basestruct.f = 3 ex_ptr-> f = 3 (*指针) - > f = 3You have almost certainly misdiagnosed the problem. Look to the linesbefore the one for which the error is reported. Simple things likemissing a '';'' on the line before may be such a culprit. Notice the useof your assignment below, which is fine. (If you had an incorrect useof ''extern'', that would probably lead to a linking error instead).#include <stdio.h>struct example_struct{int f;} basestruct = { 0};struct example_struct *ex_ptr = &basestruct;int main(void){struct example_struct **pointer;pointer = &ex_ptr;(*pointer)->f = 3;printf("basestruct.f = %d\n", basestruct.f);printf("ex_ptr->f = %d\n", ex_ptr->f);printf("(*pointer)->f = %d\n", (*pointer)->f);return 0;}basestruct.f = 3ex_ptr->f = 3(*pointer)->f = 3 这篇关于指向指针(一元“和”中的无效左值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-07 10:43