This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++ basic question about ostream class


Hi,

Is this mailing list is for C questions only?
Can I ask a c++ question.




using namespace std;
using std::ostream;

class myostream
{
        ostream &actual;

        public:
        int on;

        myostream & operator <<(char *string)
        {
                if(on)
                        actual<<string;
                return *this;
        }

}
int main()
{
        myostream t;
        t.on=1;

        t<<"HAI";
}


When I tried to compile above program I got  this compilation error.

1.cpp:2: error: ‘std::ostream’ has not been declared
1.cpp:6: error: ISO C++ forbids declaration of ‘ostream’ with no type
1.cpp:6: error: expected ‘;’ before ‘&’ token
1.cpp: In member function ‘myostream& myostream::operator<<(char*)’:
1.cpp:14: error: ‘actual’ was not declared in this scope
1.cpp: At global scope:
1.cpp:19: error: new types may not be defined in a return type
1.cpp:19: note: (perhaps a semicolon is missing after the definition
of ‘myostream’)
1.cpp:19: error: two or more data types in declaration of ‘main’

 How to solve this problem?
I searched in internet but could not found a clue.
thanks in advance.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]