Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You probably forgot to include <code>iostream</code> which makes <code>ostream</code> visible. You also need to change this into <code>std::ostream</code>, because C++ standard library names are within the namespace <code>std</code>. </p> <blockquote> <p>Do <strong>not</strong> write <code>using namespace std;</code> in a header-file, ever!</p> </blockquote> <p>It's ok to place it into the implementation file, if you want, or if you write up an example for a friend. Because any file that includes that header will have all of the standard library visible as global names, which is a huge mess and smells a lot. It suddenly increases the chance for name-clashes with other global names or other <code>using</code>'ed names - i would avoid using directives at all (see <a href="http://www.ddj.com/cpp/184401782" rel="nofollow noreferrer">Using me</a> by Herb Sutter). So change the code into this one</p> <pre><code>#include &lt;iostream&gt; // let ScaryDream be the interface class HereBeDragons : public ScaryDream { ... // mentioning virtual in the derived class again is not // strictly necessary, but is a good thing to do (documentary) virtual std::ostream &amp; print( std::ostream &amp; out ) const; ... }; </code></pre> <p>And in the implementation file (".cpp")</p> <pre><code>#include "HereBeDragons.h" // if you want, you could add "using namespace std;" here std::ostream &amp; HereBeDragons::print( std::ostream &amp; out ) const { return out &lt;&lt; "flying animals" &lt;&lt; std::endl; } </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