// William Byrd II
#include <iostream>
#include <string>
using namespace std;
class Person
{
public:
Person(const string name)
{
myName = name;
}
bool operator==(const Person& p) const
{
return (myName == p.myName);
}
private:
string myName;
};
// declares Student class as publicly inheriting from the Person class
class Student : public Person
{
public:
// implemented constructor for the Student class
Student(const string name,
const int studentId)
: Person( name )
{
myStudentId = studentId;
}
// implemented overloaded equality operator Student class member function
bool operator==(const Student& s) const
{
return (myStudentId == s.myStudentId && Person::operator==(s));
//since we want a boolean anyway we don't need the if/else
}
private:
int myStudentId;
};
int main()
{
Student app1( "William Byrd II", 8765309 );
Student app2( "William Byrd II", 8765309 );
// test overloaded == operator for Student class
cout << "app1" << ( ( app1 == app2 )
? " == " : " != " ) << "app2"
<< " according to the overloaded == operator\n";
cin.get(); //changed this from your system call
return 0;
}
I had forgotten to mention that I fleshed out your base class == sorry about that