返回信息流friend Time operator + (const Time & t1, const Time & t2)const
{
Time t3;
int m1,m2;
m1 = t1.hours * 60 + t1.minutes;
m2 = t2.hours * 60 + t2.minutes;
t3.hours = (m1 + m2) / 60;
t3.minutes =(m1 + m2) % 60;
return t3;
}
'+' : modifiers not allowed on nonmember functions,总是报这个错误,我把函数的定义放在类内类外都不行,这是为什么啊?
这是一条镜像帖。来源:北邮人论坛 / cpp / #48179同步于 2010/12/22
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
友元函数小问题求助
jmg
2010/12/22镜像同步6 回复
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
在类内我用了friend Time operator + (const Time & t1, const Time & t2)const;声明
在类外我是
Time operator+ (const Time & t1, const Time & t2)const
{
Time t3;
int m1,m2;
m1 = t1.hours * 60 + t1.minutes;
m2 = t2.hours * 60 + t2.minutes;
t3.hours = (m1 + m2) / 60;
t3.minutes =(m1 + m2) % 60;
return t3;
}
这么定义的 但还是报'+' : modifiers not allowed on nonmember functions这个错误。
【 在 ericyosho 的大作中提到: 】
: 在类外面,你有没有用 Time:: 来限定这个是一个类函数呢?
: --
声明最后的那个const去掉...友元函数不是成员函数,不能使用修饰符...
【 在 jmg (guang) 的大作中提到: 】
: 在类内我用了friend Time operator + (const Time & t1, const Time & t2)const;声明
: 在类外我是
: Time operator+ (const Time & t1, const Time & t2)const
: ...................
问题解决了,非常感谢。
【 在 shenlei 的大作中提到: 】
: 声明最后的那个const去掉...友元函数不是成员函数,不能使用修饰符...
: 【 在 jmg (guang) 的大作中提到: 】
: : 在类内我用了friend Time operator + (const Time & t1, const Time & t2)const;声明
: ...................