运算符=不从CTimeSpan类继承 [英] operator = doesn't inherited from CTimeSpan class
本文介绍了运算符=不从CTimeSpan类继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
在将CTimeSpan类继承到我的类CVoipTimeSpan后,运算符="=不被继承,然后我将代码写入继承=" =的运算符为
const CVoipTimeSpan& CVoipTimeSpan :: 运算符 =( const CVoipTimeSpan& entry)
{
如果(输入!= * 此)
{
(CTimeSpan)* 此 =(CTimeSpan)条目;
}
返回 * 此;
}
我在以下语句中测试了此代码
CTime curr_time;
CVoipTimeSpan time_span;
int time_diff_in_secs;
curr_time = CTime :: GetCurrentTime();
time_span = curr_time-database_cache_lookup_time;
time_diff_in_secs = time_span.GetTotalSeconds();
运算符-"正确完成,在time_deff_in_secs中我得到"0",为什么运算符=对我的代码进行了零修改,请回复我. > CTimeSpan::GetTotalSeconds()
返回LONG LONG
值,但是您将其存储到int
,这可能是问题所在.尝试通过调试器运行代码以查看正在生成的值.
您正在尝试定义将CVoipTimeSpan
分配给CVoipTimeSpan
的运算符. 您需要一个运算符才能将CVoipTimeSpan
分配给CTimeSpan
.
—SA
Hello all
After inheriting CTimeSpan class to my class CVoipTimeSpan the operater ''='' is not inherited then i write the code to inheriting ''='' operator as
const CVoipTimeSpan& CVoipTimeSpan::operator=(const CVoipTimeSpan& entry)
{
if (entry != *this)
{
(CTimeSpan)*this = (CTimeSpan) entry;
}
return *this;
}
i tested this code in following statements
CTime curr_time;
CVoipTimeSpan time_span;
int time_diff_in_secs;
curr_time = CTime::GetCurrentTime();
time_span = curr_time - database_cache_lookup_time;
time_diff_in_secs = time_span.GetTotalSeconds();
the operator ''-'' done correct and in time_deff_in_secs i got ''0'' why the operator = gives zero any modifications in my code please reply me .
解决方案
CTimeSpan::GetTotalSeconds()
returns aLONG LONG
value, but you are storing it to anint
, this could be the problem. Try running your code through the debugger to see what value is being generated.
You''re trying to define operator for assigningCVoipTimeSpan
toCVoipTimeSpan
.
You need an operator to assignCVoipTimeSpan
toCTimeSpan
.
—SA
这篇关于运算符=不从CTimeSpan类继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文