By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,234 Members | 2,010 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

when overloadind input/output stream operator, why return type??

P: n/a
When we overload the >> operator then why do we need to return the
istream by reference ? Why can't we do a void return?
(Quoting from a book )
e.g

istream & operator >>(istream & din, VectClass &v){
for( int i=0; i<= 3; i++)
din >> v[i];
return din;
}

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"jaivrat" <ja***********@csfb.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
When we overload the >> operator then why do we need to return the
istream by reference ?
You don't *have* to, but if you don't, you won't be
able to 'chain' calls such as:

cin >> a >> b >> c;
Why can't we do a void return?
You can if you like, but the function's use
will be more limited. Instead of the above,
you'd have to write:

cin >> a;
cin >> b;
cin >> c;

The choice is yours. :-)
(Quoting from a book )
e.g

istream & operator >>(istream & din, VectClass &v){
for( int i=0; i<= 3; i++)
din >> v[i];
return din;
}


Which book are you reading that does not explain this?

-Mike
Jul 23 '05 #2

P: n/a

Which book are you reading that does not explain this?

comp.lang.c++

Jul 23 '05 #3

P: n/a
"puzzlecracker" <ir*********@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...

Which book are you reading that does not explain this?

comp.lang.c++


That's not a book.

IMO one cannot learn a programming language by only
reading Usenet articles. You won't get far without
books.

-Mike
Jul 23 '05 #4

P: n/a
Thanks.

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.