Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Instead of this (see my comments in the code... pretty much what the compiler is telling you):</p> <pre><code>/*\ program.h \*/ typedef struct { int member0; int member1; int member2; int member3; } structure; void function(&amp;structure); /*\ program.cpp \*/ #include "program.h" int main(void) { structure *instance; // this is not an instance. it is a pointer function(instance); } void function(&amp;structure) // this is an invalid declaration { // nothing } </code></pre> <p>Do this:</p> <pre><code>/*\ program.h \*/ struct structure { int member0; int member1; int member2; int member3; }; void function(structure&amp; s); // parameter 's' is a reference to your structure /*\ program.cpp \*/ #include "program.h" int main(void) { structure instance; // this is an instance function(instance); } void function(structure&amp; s) { // nothing } </code></pre> <p>You need to appreciate the differences between instances, pointers, and references...and also know the valid syntax of each whether you are declaring variables or function interfaces.</p> <p>Alternatively, you could pass a pointer to your instance like this:</p> <pre><code>/*\ program.h \*/ struct structure { int member0; int member1; int member2; int member3; }; void function(structure* p); /*\ program.cpp \*/ #include "program.h" int main(void) { structure instance; // you still need an instance to point to function(&amp;instance); // this passes the address of the instance into the function } void function(structure* p) { // nothing } </code></pre> <p>Whether to use references or pointers depends on what you are trying to do. You should also consider using const to make it clearer whether your function will modify the contents of the struct, and also assist the compiler with optimizing your code.</p> <p>Finally, fix errors one at a time starting with the top one. Often, the second and subsequent errors change (or disappear) once the first one is fixed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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