Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Take a look at this code:</p> <pre><code>showMovieData(apocalypseNow) &lt;&lt; endl; showMovieData(theWizardOfOz) &lt;&lt; endl; </code></pre> <p>Here, <code>showMovieData</code> is a function that returns <code>void</code>, meaning that it doesn't evaluate to a value. The code you've written is then trying to apply <code>operator &lt;&lt;</code> to a nonexistent value and <code>endl</code>, which is impossible because you can't apply any operators to a <code>void</code> value.</p> <p>To fix this, consider rewriting the code as</p> <pre><code> showMovieData(apocalypseNow); cout &lt;&lt; endl; showMovieData(theWizardOfOz); cout &lt;&lt; endl; </code></pre> <p>Alternatively, replace <code>showMovieData</code> with a global <code>operator&lt;&lt;</code> operator that can be used to display objects of type <code>MovieData</code>, like this:</p> <pre><code>ostream&amp; operator&lt;&lt;(ostream&amp; out, const MovieData&amp; movie) { out &lt;&lt; "Title: " &lt;&lt; movie.title &lt;&lt; endl; out &lt;&lt; "Director: " &lt;&lt; movie.director &lt;&lt; endl; out &lt;&lt; "Year Released: " &lt;&lt; movie.yearReleased &lt;&lt; endl; out &lt;&lt; "Running Time (in minutes): " &lt;&lt; movie.runningTimeInMinutes &lt;&lt; endl; return out; } </code></pre> <p>Then, you can write</p> <pre><code>cout &lt;&lt; apocalypseNow &lt;&lt; endl; cout &lt;&lt; theWizardOfOz &lt;&lt; endl; </code></pre> <p>That said, the <code>operator&lt;&lt;</code> definition above isn't ideal because it inserts <code>endl</code> into the stream, flushing the contents, but it should also work. You may want to consider to replace <code>endl</code> inside <code>operator&lt;&lt;(ostream&amp;, const MovieData&amp;)</code> with <code>'\n'</code> which avoids the flushing.</p> <p>Hope this helps!</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