You probably forgot to include iostream
which makes ostream
visible. You also need to change this into std::ostream
, because C++ standard library names are within the namespace std
.
Do not write using namespace std;
in a header-file, ever!
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 using
'ed names - i would avoid using directives at all (see Using me by Herb Sutter). So change the code into this one
#include <iostream>
// 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 & print( std::ostream & out ) const;
...
};
And in the implementation file (".cpp")
#include "HereBeDragons.h"
// if you want, you could add "using namespace std;" here
std::ostream & HereBeDragons::print( std::ostream & out ) const {
return out << "flying animals" << std::endl;
}