// person2.cpp
#include <iostream.h>
#include <string.h>
#include <new.h>
#include "person2.h"
static char * clone(const char *s)
{
// return a copy of a string on the heap
char * p = new char[strlen(s) + 1];
return strcpy(p,s);
}
Person::Person() : birth(Date(0,0,0))
{
last = clone("");
first = clone("");
ssn = clone("");
}
Person::Person(const char * l, const char * f,
const Date& b, const char * s)
: birth(b)
{
last = clone(l);
first = clone(f);
ssn = clone(s);
}
Person::~Person()
{
delete [] last;
delete [] first;
delete [] ssn;
}
ostream& operator<<(ostream& os, const Person& p)
{
os << '{'
<< p.last << ','
<< p.first << ','
<< '[' << p.birth << ']' << ','
<< p.ssn
<< '}';
return os;
}
bool Person::operator==(const Person & p) const
{
return strcmp(last,p.last) == 0 &&
strcmp(first,p.first) == 0 &&
birth == p.birth &&
strcmp(ssn,p.ssn) == 0;
}
// End of File