感谢您的回复。 我想知道的是对象E的入口地址。 因为E-> s1.next_element是第一个成员变量,是E-> s1.next_element的地址与E的地址相同?或者是E-> s1.next_element位于同一个内存中位置为E? 我可以说(example_class *)(&(E-> s1.next_element))== E? 不,你还是不能这样做。 没有。 No. 只要struct st的变量面前,我就不能说&(E-> s1.next_elemet)= E? 不,即使这些指针包含相同的地址(我不确定是否需要),你的类型不匹配。顺便说一句,这是你第五次犯同样的错误......我错过了什么? 加两个在struct st前面的变量,对象E的入口地址 被更改了吗?对象E的入口地址是E-> s1.next_element的 地址或new_variable1的地址? 以下两个表达式: (example_class *)(&(E-> s1.next_element))== E (example_class *)(& new_variable1)== E 哪一个是正确的? 非常感谢。 杰克 Suppose that I define the following class: class example_class{ public:example_class();void funtion_1();void function_2(); protected:struct st {example_class *next_element;example_class *prev_element;} s1; int variable_1;double variable_2; private:int *variable_3;} Then I create four objects:example_class *A;example_class *B;example_class *C;example_class *D; And link them togother as a linked list: A-B-C-D.Then I create a new object E and want to insert E before C.Below is what I do: example_class *E; E->s1.next_element = C;E->s1.prev_element = B;C->s1.prev_element = &(E->s1.next_elemet);B->s1.next_element = &(E->s1.next_element); Are above operation correct? For the last two sentences, I can alsowrite:C->s1.prev_element = E;B->s1.next_element = E;I think &(E->s1.next_elemet)= E, am I right? --------------------------------------Below is another situation:I modify the defination of example_class to be: class example_class{ public:example_class();void funtion_1();void function_2(); double new_variable1; //I add two variablesint new_variable2; // in front of the strust st.protected:struct st {example_class *next_element;example_class *prev_element;} s1; int variable_1;double variable_2; private:int *variable_3;} After I add two new variables in front of struct st, can I still dothe same operation as above example? That is: With a linked list: A-B-C-D same as above.Then I create a new object E and want to insert E before C.Below is what I do: example_class *E; E->s1.next_element = C;E->s1.prev_element = B;C->s1.prev_element = &(E->s1.next_elemet);B->s1.next_element = &(E->s1.next_element): Are the above operation correct?With two new variables added in front of struct st, can I stillsay that &(E->s1.next_elemet)=E ?As long as there is variable infront of struct st, I can notsay &(E->s1.next_elemet)=E ?If possible, please give your correction. Thanks a lot. Jack 解决方案 That''s much better. No, those pointers have different types. Thanks for responding.What I want to know is the entry address of object E.Since E->s1.next_element is the first memeber variable, is theaddress of E->s1.next_element same as the address of E?Or is E->s1.next_element located in the same memory location as E?Can I say that (example_class *)(&(E->s1.next_element))== E ? No, you still can''t do it. No. No. No, even if those pointers contain the same address (I''m not sure whether that''s required), you''ve got a type mismatch. By the way, that''s the fifth time you''ve made the same typo... Am I missing something? After adding two variable in front of struct st, has the entry addressof object E been changed? The entry address of object E is theaddress of E->s1.next_element or the address of new_variable1? The following two expression:(example_class *)(&(E->s1.next_element))== E(example_class *)(&new_variable1)== E which one is correct? Thanks a lot. Jack 这篇关于链接的对象列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 11-03 15:31