I have never tried to extend ostream before but now I must in order to easily switch between sending to cout and sending to a socket. Thus I have
-----
class SockStreamublic ostream{
private:
Server *server;
public:
explicit SockStream(Server *);
SockStream& operator <<(char*);
SockStream& operator <<(int );
};
-----
The strange thing is that when I do
------
Sockstream sout(server);
if(!sout)
cout << "Could not find sout" << endl;
recvfrom(.....);
sout << "hello\n";
------
it gives me:
...
bash$ ./cerver 8907
Could not find sout
...
but:
...
bash$ ./client 127.0.0.1
hello
....
My point being that it creates an object that is apparently 0, yet then is able to use it for some reason. Is there any reason that extending ostream is not straight foward?
QUESTION 2:
how do I make it so that my SockStream can do:
sout << "hello" << endl; // ie. with the endl
I dont know anything about what endl is, it gives me this compiler error:
no match for 'SockStream & << ostream & (&)(ostream &)'
any idea?