Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, the signature of your data() function:</p> <pre><code>bool data(struct *sampleData) </code></pre> <p>cannot possibly work, because the argument lacks a name. When you declare a function argument that you intent to actually access, it needs a name. So change it to something like:</p> <pre><code>bool data(struct sampleData *samples) </code></pre> <p>But in C++, you don't need to use <code>struct</code> at all actually. So this can simply become:</p> <pre><code>bool data(sampleData *samples) </code></pre> <hr> <p>Second, the <code>sampleData</code> struct is not known to data() at that point. So you should declare it before that:</p> <pre><code>struct sampleData { int N; int M; string sample_name; string speaker; }; bool data(sampleData *samples) { samples-&gt;N = 10; samples-&gt;M = 20; // etc. } </code></pre> <p>And finally, you need to create a variable of type <code>sampleData</code>. For example, in your main() function:</p> <pre><code>int main(int argc, char *argv[]) { sampleData samples; data(&amp;samples); } </code></pre> <p>Note that you need to pass the address of the variable to the data() function, since it accepts a pointer.</p> <p>However, note that in C++ you can directly pass arguments by reference and don't need to "emulate" it with pointers. You can do this instead:</p> <pre><code>// Note that the argument is taken by reference (the "&amp;" in front // of the argument name.) bool data(sampleData &amp;samples) { samples.N = 10; samples.M = 20; // etc. } int main(int argc, char *argv[]) { sampleData samples; // No need to pass a pointer here, since data() takes the // passed argument by reference. data(samples); } </code></pre>
 

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