Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Operator= Causing Unhandled Exceptions

Status
Not open for further replies.

Kalisto

Programmer
Feb 18, 2003
997
GB
I have inherited a project that doesnt work, from someone who has since been persuaded to leave the company.

There are currently a number of things I cannot get working on this project, the biggest culprit is below

I have an Operator= Defined like

Code:
CPatient& CPatient::operator=(CPatient& p)
{
m_PostCode = p.GetPostCode();
m_Country=p.GetCountry();
m_Comment=p.GetComment(); 
m_State=p.GetState();
m_City=p.GetCity();
m_Adress=p.GetAdress();
m_DOB=p.GetDOB();
m_Doctor=p.GetDoctor();
m_ID=p.GetID();
m_FirstName=p.GetFirstName();
m_LastName =p.GetLastName();
m_Sex=p.GetSex();
return *this;
}

and a Global Patient Object, that I am updating via the equals.

Before the =, the CurrentPatient, and the temporary patient hold correct data.
During the assignment, I get an Unhandled Exception during the GetComment() function.

Can anyone suggest ways of tracking this error down, or common faults I can check to eliminate this issue?

Thanks
K
 
That is Okay but your code should look like here:
Code:
CPatient& CPatient::operator=(CPatient& p)
{
	if ( this != &p ) 
	{      // Copy 
		m_PostCode = p.GetPostCode();
		m_Country=p.GetCountry();
		m_Comment=p.GetComment(); 
		m_State=p.GetState();
		m_City=p.GetCity();
		m_Adress=p.GetAdress();
		m_DOB=p.GetDOB();
		m_Doctor=p.GetDoctor();
		m_ID=p.GetID();
		m_FirstName=p.GetFirstName();
		m_LastName =p.GetLastName();
		m_Sex=p.GetSex();
	}
	return *this;
}
-obislavu-
 
Thanks, good point, else Im copying needlessley sometimes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top