operator<< overload,

Posted by mr.low on Stack Overflow See other posts from Stack Overflow or by mr.low
Published on 2010-04-23T02:10:15Z Indexed on 2010/04/23 2:13 UTC
Read the original article Hit count: 436

Filed under:
|
|
|
|

//using namespace std;

using std::ifstream;

using std::ofstream;

using std::cout;

class Dog {

friend ostream& operator<< (ostream&, const Dog&);

public:
    char* name;
    char* breed;
    char* gender;

    Dog();
    ~Dog();

};

im trying to overload the << operator. I'm also trying to practice good coding. But my code wont compile unless i uncomment the using namespace std. i keep getting this error and i dont know. im using g++ compiler. Dog.h:20: error: ISO C++ forbids declaration of ‘ostream’ with no type Dog.h:20: error: ‘ostream’ is neither function nor member function; cannot be declared friend. if i add line using std::cout; then i get this error. Dog.h:21: error: ISO C++ forbids declaration of ‘ostream’ with no type. Can somebody tell me the correct way to overload the << operator with out using namespace std;

© Stack Overflow or respective owner

Related posts about operator

Related posts about c++