由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - operator++ 返回值问题
相关主题
请问C++返回值和返回引用区别关于函数返回值的问题
请教大虾们一个C++返回值问题一道笔试题
刚看完类这一章,有些大小问题,请指教,谢谢你们都检查这些system call的返回值吗?
师傅们都出来看看吧,我也问个C++返回值问题。门外汉求教 return statement用法
C++的exception大家常用吗?C# and WPF 类的转换
C编译器为何允许一个函数在某个路径不返回值?请教一个OOP的C++问题
经过两个月,矩阵库基本完成,c++11就是好
相关话题的讨论汇总
话题: number话题: postfix话题: operator话题: reference话题: prefix
进入Programming版参与讨论
1 (共1页)
z****e
发帖数: 2024
1
class Number {
public:
Number& operator++ (); // prefix ++
Number operator++ (int); // postfix ++
};
why should the prefix version returns by reference, the postfix version by
value? why not both by reference?
X****r
发帖数: 3557
2
Just try to write an overloaded postfix++ that returns a reference,
you'll understand.

by

【在 z****e 的大作中提到】
: class Number {
: public:
: Number& operator++ (); // prefix ++
: Number operator++ (int); // postfix ++
: };
: why should the prefix version returns by reference, the postfix version by
: value? why not both by reference?

S*********g
发帖数: 5298
3
I would suggest OP to read thinking in C++ about this issue.
There is a full discussion about this.

【在 X****r 的大作中提到】
: Just try to write an overloaded postfix++ that returns a reference,
: you'll understand.
:
: by

z****e
发帖数: 2024
4
i didn't write it, but i suddenly realized, after reading your post, that
the tmp object will be destroyed after the postfix op++ returns. so must
return by value right?

【在 X****r 的大作中提到】
: Just try to write an overloaded postfix++ that returns a reference,
: you'll understand.
:
: by

z****e
发帖数: 2024
5
actually, i worked it through one year ago page by page. but now, i forget
60% of it. so bad:(
how to remember, is still my trouble.

【在 S*********g 的大作中提到】
: I would suggest OP to read thinking in C++ about this issue.
: There is a full discussion about this.

S*********g
发帖数: 5298
6
well, you have to understand the concept not just memorizing the result

【在 z****e 的大作中提到】
: actually, i worked it through one year ago page by page. but now, i forget
: 60% of it. so bad:(
: how to remember, is still my trouble.

X****r
发帖数: 3557
7
Totally agree, and I should go further to say there should be very
little thing to memorize from any book at all. Everything worth
learning is either fact or logic. For fact you can always look it up
later when needed so you only need to know where is the reference.
For logic you should be able to deduce it yourself if you really
understand it. Thus my advice for beginner is that don't try too
hard to memorize anything.

【在 S*********g 的大作中提到】
: well, you have to understand the concept not just memorizing the result
z****e
发帖数: 2024
8
谨遵师嘱。
我就在理解的基础上记忆吧。

【在 X****r 的大作中提到】
: Totally agree, and I should go further to say there should be very
: little thing to memorize from any book at all. Everything worth
: learning is either fact or logic. For fact you can always look it up
: later when needed so you only need to know where is the reference.
: For logic you should be able to deduce it yourself if you really
: understand it. Thus my advice for beginner is that don't try too
: hard to memorize anything.

1 (共1页)
进入Programming版参与讨论
相关主题
请教大虾们一个C++返回值问题一道笔试题
刚看完类这一章,有些大小问题,请指教,谢谢你们都检查这些system call的返回值吗?
师傅们都出来看看吧,我也问个C++返回值问题。门外汉求教 return statement用法
C++的exception大家常用吗?C# and WPF 类的转换
C编译器为何允许一个函数在某个路径不返回值?请教一个OOP的C++问题
经过两个月,矩阵库基本完成,c++11就是好请问C++返回值和返回引用区别
关于函数返回值的问题
相关话题的讨论汇总
话题: number话题: postfix话题: operator话题: reference话题: prefix