c++ - identifier "ostream" is undefined error -


i need implement number class support operator << output. have error: "identifier "ostream" undefined" reason eventhough included , try

here header file:

number.h

#ifndef number_h #define number_h #include <iostream> class number{ public: //an output method (for type inheritance number): virtual void show()=0;  //an output operator: friend ostream& operator << (ostream &os, const number &f);   };  #endif 

why compiler isnt recognize ostream in friend function?

you need qualify name ostream name of namespace class lives in:

    std::ostream //  ^^^^^ 

so operator declaration should become:

friend std::ostream& operator << (std::ostream &os, const number &f); //     ^^^^^                      ^^^^^ 

alternatively, have using declaration before unqualified name ostream appears:

using std::ostream; 

this allow write ostream name without full qualification, in current version of program.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -