Assume the existence of a File class with boolean data member, isValid, indicati
ID: 3530141 • Letter: A
Question
Assume the existence of a File class with boolean data member, isValid, indicating the file is ready for I/O. Write a unary operator, !, that accepts a constant File reference, and returns true if the file is not ready for I/O and false otherwise. My Code: bool File operator !(bool File& isValid) { if(isValid) { return (!isValid); } else { return (isValid); } } Error Message: CTest.cpp:3: error: expected ';' before 'operator' CTest.cpp:15: error: expected `;' at end of input CTest.cpp:15: error: expected `}' at end of input CTest.cpp:15: error: expected unqualified-id at end of input I'm kind of stumped, the book doesn't cover this in any real detail (a paragraph or two at most) so I'm not sure what the correct C++ syntax is. I imagine it shouldn't be hard for anyone who has real exprience in C++Explanation / Answer
this works in CodeLab:
bool operator!() { return !isValid;};
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.