Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to dereference a pointer to a structure pointer in C++
    text
    copied!<p>I have been working around with the bsd-list. And I wrote a very simple program to insert simple integer elements by creating the list. The code is as follows.</p> <pre><code>#include&lt;iostream&gt; #include&lt;stdlib.h&gt; #include"bsd-list.h" using namespace std; struct foo { int a; LIST_ENTRY(foo) pointers; // pointers is the object of the structure generated by List Entry } *temp, *var, *ptr; LIST_HEAD(foo_list, foo); int main(void) { LIST_HEAD(foo_list, foo) head; LIST_INIT(&amp;head); struct foo *item1 = new foo; struct foo *item2 = new foo; struct foo *item3 = new foo; item1-&gt;a = 60; item2-&gt;a = 120; item3-&gt;a = 240; LIST_INSERT_HEAD(&amp;head, item1, pointers); LIST_INSERT_AFTER(item1, item2, pointers); LIST_INSERT_BEFORE(item2, item3, pointers); //Displaying inner details of list { cout&lt;&lt;"HEAD's Address : "&lt;&lt;head.lh_first&lt;&lt;endl; cout&lt;&lt;"Item 1 next value : "&lt;&lt;(item1)-&gt;pointers.le_next&lt;&lt;endl; cout&lt;&lt;"Item 1 prev value : "&lt;&lt;*(item1)-&gt;pointers.le_prev&lt;&lt;endl; cout&lt;&lt;"HEAD's Address : "&lt;&lt;head.lh_first&lt;&lt;endl; cout&lt;&lt;"Item 2 next value : "&lt;&lt;item2-&gt;pointers.le_next&lt;&lt;endl; cout&lt;&lt;"Item 2 prev value : "&lt;&lt;*(item1)-&gt;pointers.le_prev&lt;&lt;endl; cout&lt;&lt;"HEAD's Address : "&lt;&lt;head.lh_first&lt;&lt;endl; cout&lt;&lt;"Item 3 next value : "&lt;&lt;item3-&gt;pointers.le_next&lt;&lt;endl; cout&lt;&lt;"Item 3 prev value : "&lt;&lt;*(item3)-&gt;pointers.le_prev&lt;&lt;endl; } ptr = head.lh_first; for(;;ptr = ptr-&gt;pointers.le_next) { cout&lt;&lt;ptr-&gt;a&lt;&lt;endl; } return (0); } </code></pre> <p>using the statement <code>*(item1)-&gt;pointers.le_prev</code> I am getting the value at the address contained in <code>le_prev</code>.</p> <p>However I want to do something like <code>**(item1)-&gt;pointers.le_prev</code> so that I get the value 60. But I am getting errors. What is the proper syntax to correctly use dereferencing?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload