On Mon, Oct 6, 2008 at 9:31 PM, tery_bboy <[EMAIL PROTECTED]> wrote:
> Hello, I've been doing some operator overloading and i've pretty much
> covered the whole thing, except the insertion and extraction
> operators.
>
> I've got two questions:
> 1. I've seen in my book as well as many sites on line that those two
> operators can only be overloaded using friend functions. Can't we use
> member functions instead? I've tried doing it... but didn't up come
> with a way of refering to streams inside the function...

http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.8

> 2. The two operators (<< and >>) are binary operators. By obvious
> logic, the function of the overloaded binary operator should always
> return a value. for the operators << and >> where is this value
> returned to.

They should return a stream. The stream returned allows you to chain
the operators:

cout << "string " << 1;

If they didn't return the stream the above wouldn't work - you'd only
be able to use one <<.

You typically return the stream that was passed in.

-- 
PJH

http://shabbleland.myminicity.com/ind

Reply via email to