Reference function:
// the getDept() function shall be defined as a reference function. That is, a call to this function will copy the
// member variable m_iDeptID into the int variable referenced by the function argument
void EmployeeRecord::getDept(int& d)
{
d = m_iDeptID;
}
Pointer function:
// the getSalary() function shall be defined as a pointer function. That is, a call to this function will copy the
// member variable m_dSalary into the int variable pointed to by the function argument
void EmployeeRecord::getSalary(double *sal)
{
*sal = m_dSalary;
}
Destructor (I don't have any delete statements, or anything, in the function):
// destructor - cleans up and deallocates any memory that pointers within this class may have referenced to
EmployeeRecord::~EmployeeRecord(){}
My attempt at explicitly calling the destructor:
EmployeeRecord Employee1;
Employee1.~EmployeeRecord();
So my questions are: (1) Are my reference and pointer functions consistent with their descriptions? (2) If they are, what code should I put into the block of my destructor so that I can call the destructor explicitly, and it successfully "cleans up and deallocates any memory that pointers within this class may have referenced to" (if there is, in fact, anything I need to put in the body of the destructor)?
In turn:
getDept(int &d)
is consistent with its description, but getSalary(double *d)
isn't quite: the description says it should copy the value into the int variable pointed to by the function argument.
getSalary
then should take a int *
argument, instead of a double *
argument, and the method should perform the appropriate cast. (This does seem a bit of an odd specification though — sure it wasn't meant to say double rather than int?)
int
s and double
s and so on. Are there any members that are pointers?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.