question about operator bool() const

when checking if an object has valid data do we need to check every private member of the class or only one? For example:
class Student {
int no;
float grade[NG];
int ng;
class Student {
int no;
float grade[NG];
int ng;
In the OOP notes the conversion operator for bool only checks that one member is not zero or true Like this: Student::operator bool() const { return no != 0; } Long story short do we need to check every member is true or only one for it to be considered valid data in an object?
4 Replies
the magic guy
the magic guy3y ago
It’s how ever you deem a student to be a “valid student” Depends on your logic ig
sesame.seed2
sesame.seed2OP3y ago
so say a student would not be valid if their grade is empty then i would have to do something this.. Student::operator bool() const { return no != 0 && grade!= 0; } ??
the magic guy
the magic guy3y ago
Yes basically
sesame.seed2
sesame.seed2OP3y ago
thank you!
Want results from more Discord servers?
Add your server