c++ basic question about ostream class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux