I have two classes and one of them is inherited from the other class.
Class Person - used to store first name and last name of a person. The data members are protected.
Class Candidate - used to store votes of an election, and this is inherited from Person class so that I can store name of the candiadate.
I have overloaded these operators in Person class : ==, !=, <, <=, >, >=
I have also overloaded the same operators in Candidate class too but the definision are same because you can only use the name of the candidate to compare. So rather than copy and paste the same code, I used static_cast. It worked but I wonder is it bad to do like that?
Ex:
bool Candidate::operator ==(const Candidate& right) const
{
//return (firstName == right.firstName && lastName == right.lastName);
// Rather than the above, I used this...
return (static_cast<Person>(*this) == static_cast<Person>(right));
}