c++ basic question about ostream class
ranjith kumar
ranjithproxy@gmail.com
Fri Mar 27 22:00:00 GMT 2009
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.
More information about the Gcc-help
mailing list