📄 subject_62303.htm
字号:
<p>
序号:62303 发表者:Cxt_ann 发表日期:2003-11-26 07:18:20
<br>主题:为何出错?
<br>内容:程序如下:<BR>//mytime0.h文件<BR>#ifndef MYTIME0_H_<BR>#define MYTIME0_H_<BR><BR>#include <iostream.h><BR>//using namespace std;<BR>class Time<BR>{<BR>private:<BR> int hours;<BR> int minutes;<BR>public:<BR> Time ();<BR> Time (int h, int m = 0);<BR> void AddMin (int m);<BR> void AddHr (int h);<BR> void Reset (int h = 0, int m = 0);<BR> Time Sum (const Time & t) const;<BR> //Time operator+ (const Time & t) const;<BR> void Show () const;<BR>};<BR><BR>#endif<BR><BR>//mytime0.cpp文件<BR>#include "mytime0.h"<BR>#include <iostream.h><BR><BR>Time::Time ()<BR>{<BR> hours = minutes = 0;<BR>} <BR><BR>Time::Time (int h, int m)<BR>{<BR> hours = h;<BR> minutes = m;<BR>}<BR><BR>void Time::AddMin (int m)<BR>{<BR> minutes += m;<BR> hours += minutes / 60;<BR> minutes %= 60;<BR>}<BR><BR>void Time::AddHr (int h)<BR>{<BR> hours += h;<BR>}<BR><BR>void Time::Reset (int h, int m)<BR>{<BR> hours = h;<BR> minutes = m;<BR>}<BR><BR>Time Time::Sum (const Time & t) const<BR>//Time Time::operator+ (const Time & t) const<BR>{<BR> Time sum;<BR> sum.minutes = minutes + t.minutes;<BR> sum.hours = hours + t.hours + sum.minutes / 60;<BR> sum.minutes %= 60;<BR> return sum;<BR>}<BR><BR>void Time::Show () const<BR>{<BR> cout << hours << " hours, " << minutes << " minutes" << endl;<BR>}<BR><BR>//usetime0.cpp文件<BR>#include <iostream.h><BR>#include "mytime0.h"<BR>//using namespace std;<BR><BR>void main()<BR>{<BR> Time A;<BR> Time B (5,40);<BR> Time C (2,55);<BR><BR> cout << "A = ";<BR> A.Show();<BR> cout << "B = ";<BR> B.Show();<BR> cout << "C = ";<BR> C.Show();<BR><BR> A = B.Sum;<BR> //A = B.operator+;<BR> cout << "B.Sum = ";<BR> A.Show();<BR>}<BR><BR>在编译的时候,总是为何出来<BR>“d:\program files\microsoft visual studio\myprojects\plus310\usetime0.cpp(18) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class Time (__thiscall Time::*)(const class Time &) const' (or there is no accepta”<BR>哪里错了?请纠正。<BR>另外:Time Time::Sum (const Time & t) const 的调用过程是怎样的?请详细说明,谢谢各位了!!!
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:CDMA2000 回复日期:2003-11-26 09:15:59
<br>内容:A = B.Sum有问题,你没有为你的类定义"="操作符
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:dstwwx 回复日期:2003-11-26 09:21:59
<br>内容: A = B.Sum;<BR>本身语句有问题,Sum是一个函数。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:萨达姆的黑手掌 回复日期:2003-11-26 09:54:13
<br>内容:B.Sum(t);<BR>好歹带个参是吧?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Cxt_ann 回复日期:2003-11-26 11:15:30
<br>内容:多谢萨达姆的黑手掌!!!<BR>改成B.Sum(C)就对了,太感谢了,小弟茅塞顿开!!!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -