avatar
选择, 还是爱自己# Love - 情爱幽幽
h*b
1
class xyz
{
public:
xyz &operator=(const xyz &rhs);
const xyz& operator+(const xyz &rhs) const;
const xyz& operator+(int m);
private:
int n;
};
main()
{
xyz a,b,c;
a=b+c+5; //为啥不对: binary '+' : no operator found which takes a right-
hand operand of type 'int' (or there is no acceptable conversion)
}
感谢
avatar
o*z
3
也曾因无限的温柔迷惘,
也曾被绝美的外表沉醉,
也曾因为他的小心翼翼的呵护,善解人意的包容,
也曾因为他的聪明伶俐的孩子气,
感动,但还是轻易选择放手,选择爱自己,
按他的话说,"只有自己知道什么是对自己最好的"
avatar
b*h
4
You are missing a "const" in const xyz& operator+(int m) 'const';
avatar
c*h
5
zephyr卖点是self cleaning, 妈妈乐卖点是易拆洗。
我只用过妈妈乐, 拆起来还比较容易
avatar
d*r
6
没听懂
到底是谁爱自己啊
好像说的是对方吧...

【在 o*z 的大作中提到】
: 也曾因无限的温柔迷惘,
: 也曾被绝美的外表沉醉,
: 也曾因为他的小心翼翼的呵护,善解人意的包容,
: 也曾因为他的聪明伶俐的孩子气,
: 感动,但还是轻易选择放手,选择爱自己,
: 按他的话说,"只有自己知道什么是对自己最好的"

avatar
c*l
7
1) b+c+5; execute from left to right.
b+c ->
const xyz& operator+(const xyz &rhs) const;
get const reference.
+5 ->
no const xyz& operator+(int m) const defined.
so get the problem
2)
I dont know why you need signature
const xyz& operator+(const xyz &rhs) const;
it might be better to define
xyz operator +( const xyz &left, const xyz &right) as friend
hope helpsl

【在 h****b 的大作中提到】
: class xyz
: {
: public:
: xyz &operator=(const xyz &rhs);
: const xyz& operator+(const xyz &rhs) const;
: const xyz& operator+(int m);
: private:
: int n;
: };
: main()

avatar
c*1
8
只有自己知道什么是对自己最好的
avatar
h*b
9
thanks a lot. This is actually an interview question to find a fault.
avatar
z*9
10
what is the point of returning const reference if you have to do "+"?
avatar
e*c
11
(1)const xyz& operator+(const xyz &rhs) const;

(2)const xyz& operator+(const xyz &lhs, const xyz &rhs) const;
有什么区别?
我不太明白用(1)的话, a=b+c 是如何实现的?

【在 c****l 的大作中提到】
: 1) b+c+5; execute from left to right.
: b+c ->
: const xyz& operator+(const xyz &rhs) const;
: get const reference.
: +5 ->
: no const xyz& operator+(int m) const defined.
: so get the problem
: 2)
: I dont know why you need signature
: const xyz& operator+(const xyz &rhs) const;

avatar
a*u
12
(1) 不能 调换加的顺序 , 不是完全的 加法,
(2) 可以任意 调换 加的顺序, 是完全的加法。

【在 e**c 的大作中提到】
: (1)const xyz& operator+(const xyz &rhs) const;
: 和
: (2)const xyz& operator+(const xyz &lhs, const xyz &rhs) const;
: 有什么区别?
: 我不太明白用(1)的话, a=b+c 是如何实现的?

avatar
a*u
13
补充一点
(1)必须把 operator+ 定义在 class 里面
(2)要把 operator+ 定义成global 函数,然后 declare成 class 的 friend 函数

【在 a********u 的大作中提到】
: (1) 不能 调换加的顺序 , 不是完全的 加法,
: (2) 可以任意 调换 加的顺序, 是完全的加法。

avatar
e*c
14
那(2)为什么要定义成global函数呢?是因为它与class成员无关吗?

【在 a********u 的大作中提到】
: 补充一点
: (1)必须把 operator+ 定义在 class 里面
: (2)要把 operator+ 定义成global 函数,然后 declare成 class 的 friend 函数

avatar
P*b
15
因为在成员里面第一个参数默认为this

【在 e**c 的大作中提到】
: 那(2)为什么要定义成global函数呢?是因为它与class成员无关吗?
avatar
r*e
16
弱问一下,xyz& operator+(int m) “const”, 最后那个const表示什么意思?是不
是说first
operand is const?
const xyz& operator+(const xyz &rhs) “const”, 需要这个设成const吗?
谢了

【在 c****l 的大作中提到】
: 1) b+c+5; execute from left to right.
: b+c ->
: const xyz& operator+(const xyz &rhs) const;
: get const reference.
: +5 ->
: no const xyz& operator+(int m) const defined.
: so get the problem
: 2)
: I dont know why you need signature
: const xyz& operator+(const xyz &rhs) const;

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。