« first day  last day (15 days later) » 

12:04 AM
why pass by reference? why not by value?
 
 
8 hours later…
8:24 AM
Pass by value implies that a copy is being made. But since you are not changing the dictionary after it has been loaded, just passing a reference to the dictionary avoids the copy, so it is more efficient.
 
 
2 hours later…
9:55 AM
ah, I see. And const is used, because otherwise the function could change the dictionary?
 
10:45 AM
what can happen to the input? in the std::getline paragraph you mention it, but I don't know what bad can happen.
 
11:23 AM
There are many things that can happen with the input. If someone redirects a file or a network socket to standard input, there might be a disk or network error. But even if you read from the keyboard, the user can close the input. On UNIX systems, this can simply be done by pressing control-D. Whatever the reason, if any of the above happens, then the functions reading the input will immediately return.
If you don't check for errors, but keep trying to read valid input in a loop, then your program will start using 100% CPU time doing nothing useful.
 
11:42 AM
mmh, so suppose something is indeed bad with the input, in the error handling if-statement, I need cin.clear and cin.ignore to make state clean again or? Also, should I let the user know in this case?
 
Clearing the error state and ignoring things will not make a problem go away. The error would just be detect by the next call to std::getline() or when doing std::cin >> somevar. You have to check the state of std::cin, and if it is not OK, then you have to just terminate your program somehow. The easiest way is to just write if (!std::cin) { std::cerr << "Error occured on input\n"; return/exit()/throw; }
 
12:43 PM
ok I think I followed every tip you gave me in the topic, should I edit my question so that the overworked code can be seen?
acutally no, I didn't use pass by const reference everywhere where its suitable!
 
1:42 PM
Can you look through this and tell me if it's ok or if there is still some bad design in it. pastebin.com/FckftBy0
 

« first day  last day (15 days later) »