try catch - c++ error handling return values error returned -


i have class have been given error input handling for. it's class has been given it's own "extraction" operator , i've been asked implement code i've been given. problem i'm having code should use looks similar this.

try {     while (some condition)     {....implemented code....} } catch (runtime_error& e) {     cerr << e.what() << endl;     return 1; } 

the problem having compiling doesn't seem "return 1" value gives me error of:

invalid initialization of non-const reference of type ‘std::istream& {aka std::basic_istream<char>&}’ rvalue of type ‘int’ 

if remove return value compiles straight program fails execute once hits area trying try statement. mentioned code have there above example code supposed implement assumed straight out of box work. condition while loop was

while (!std::cin.fail()) 

as assumed i'd want keep getting input until fails reason. why return values in case causing problem?

psychic debugging indicates:

your enclosing function has signature of form

std::istream& func_name(/*parameter list goes here*/) 

hence compilation error


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -