I'm new to c++ and i have a question about the following code below. Is it true that the line "if(p1.spouse || p2.spouse) return false
" is another way saying "
if(p1.spouse!= NULL || p2.spouse!=NULL)return false
" ?
struct Person
{
string name;
string bday;
int height;
Person* spouse;
};
bool marry(Person&, Person&);
int main()
{
Person john;
john.name = "John";
john.bday = "May 29, 1917";
john.height = 72;
john.spouse = NULL;
Person marilyn;
marilyn.name = "Marilyn";
marilyn.bday = "06/01/1926";
marilyn.height = 64;
marilyn.spouse = NULL;
marry(john, marilyn);
cout << "John is married to " << john.spouse->name << endl;
}
bool marry(Person& p1, Person& p2)
{
if (p1.spouse || p2.spouse) return false;
p1.spouse = &p2;
p2.spouse = &p1;
return true;
}