![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jan 2006
Posts: 58
Rep Power: 3
![]() |
while loop question
while ( src >> word){ //code };In this case, does (src >> word) actually do my overload for >>? Or does it just check if it's possible, then enter the loop? I hope that makes sense...!! Thanks! |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Mar 2006
Posts: 15
Rep Power: 0
![]() |
while loops don't check if things are possible, they evaluate whether or not they are true.
|
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jan 2006
Posts: 58
Rep Power: 3
![]() |
That's what I meant by if it's possible. The way I said it was ambiguous.
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
Yes, it will perform the operations in the brackets.
|
|
|
|
|
|
#5 |
|
Programmer
Join Date: Jan 2006
Posts: 58
Rep Power: 3
![]() |
Thanks.
|
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Yes?
Depends on what the insertion operator (which the OP says is overloaded) has been written to return. That's not an item of information given in the post.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#7 |
|
Hobbyist Programmer
|
It performs what ever it’s instructed to in the brackets. Whether it continues into the braces depends on the return value as DaWei said. Unless I’m wrong again.
|
|
|
|
|
|
#8 |
|
Programmer
Join Date: Jan 2006
Posts: 58
Rep Power: 3
![]() |
ifstream& operator>>(ifstream& fin, const WordData &curWordData);
Returns fin. |
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
The insertion operator typically returns the stream (a reference). Even if insertion fails, the return will not be zero unless the function is specifically written to do that. Failures are tested with other methods (e.g., good (), eof (), fail (), etc.).
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#10 |
|
Programmer
Join Date: Mar 2006
Location: Tennessee
Posts: 41
Rep Power: 0
![]() |
I think he was asking if the code as written actually does the overloading. Answer to that is, no. You have to write it into a function how you want it overloaded.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|