I'm attempting to check if one of my bool functions return true or not and it would return that to my overloaded << operator..however im getting an error when i try to do if(isClear())
Here is a part of my .cpp file that is relevant to my problem..
1 2 3 4 5 6 7 8 9 10 11 12 13
constchar* ErrorMessage::message()const{ // returns the error message
return message_;
}
bool ErrorMessage::isClear()const{ // returns true if the message is empty ( NO Error)
return message_ == 0;
}
std::ostream& operator<<(std::ostream& os, const ErrorMessage& M){ // prints the ErrorMessage object using ostream
if (ErrorMessage::isClear()){
return os << M.message();
}
}
If you are going to have a polymorphic class, you probably need to do the rule of five (six?, counting the dtor) and default all of the special member functions, have a look at the example at the end.
Also, you have a virtual dtor, but no other virtual functions; no pure virtual. Presumably a derived class will have some of those? Or this class might not need to be polymorphic?
Is there a reason why you use char * rather than std::string? You probably have a good reason, I am just curious :+)