参考功能:
// 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;
}
指针功能:
// 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 - cleans up and deallocates any memory that pointers within this class may have referenced to
EmployeeRecord::~EmployeeRecord(){}
我尝试显式调用析构函数:
EmployeeRecord Employee1;
Employee1.~EmployeeRecord();
所以我的问题是: (1)我的引用和指针功能是否与其描述一致? (2)如果是,我应该将什么代码放入析构函数的块中,以便我可以显式调用析构函数,并且它成功地“清理并释放此类中指针可能引用的任何内存”(如果有的话)事实上,我需要放入析构函数体中的任何东西)?
答案 0 :(得分:0)
反过来:
getDept(int &d)
与其描述一致,但getSalary(double *d)
并不完全:描述说它应该将值复制到指向的 int 变量中通过函数参数。
getSalary
然后应该使用int *
参数而不是double *
参数,并且该方法应该执行适当的强制转换。 (这确实看起来有点奇怪 - 确定它不是说双重而不是整数?)
int
和double
s等等。是否有任何指针成员?