This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
c++ basic question about ostream class
- From: ranjith kumar <ranjithproxy at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 28 Mar 2009 03:30:09 +0530
- Subject: 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.