由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - [C++] 入门级问题 increment and decrement operators
相关主题
请问C++返回值和返回引用区别C++高手请进,内存管理问题
ambiguous operators in c++inline functions in C++
question overloading ++ errorthrust help ~~~
overload "++i"里的operator“++”,怎么declare?求题目
ostream& operator << (ostream& s, int cnt) error求题目
member and friend请教boost::any compile错误。
一个C++语法问题Help C++ Template function link error .
C++ func overload questiona C++ question
相关话题的讨论汇总
话题: upint话题: f1话题: c++话题: function话题: f2
进入Programming版参与讨论
1 (共1页)
G****A
发帖数: 4160
1
***************
class UPInt {
public:
UPInt& operator++(); %function F1
const UPInt operator++(); %function F2
...
};
******************
UPInt i;
int a;
++i; %(1)
i++; %(2)

我觉得按照语法,(2)应该call F1;(1)应该no matched function defined. 但实际
(2)call F2, (1)call F1. 请问compiler用什么rule来决定matching的?
希望我的描述还算清楚。
t****t
发帖数: 6806
2
你的描述一点也不清楚, 按你这个描述肯定是编译通不过的. 除了你是在写C++而不是
matlab, 注释应该用//而不是%以外, 这两个overloading也是不能编译的. 如果你不会
抄的话, 还是copy/paste来得比较容易.

【在 G****A 的大作中提到】
: ***************
: class UPInt {
: public:
: UPInt& operator++(); %function F1
: const UPInt operator++(); %function F2
: ...
: };
: ******************
: UPInt i;
: int a;

G****A
发帖数: 4160
3
这个问题是朋友问我的,所以我也没有source.
但让我confuse的部分是:
如果有一个member function: UPInt& operator++();
那么对于 UPInt A; A++; ++A; which one is a valid call to the member function?
谢谢大牛耐心解释.

【在 t****t 的大作中提到】
: 你的描述一点也不清楚, 按你这个描述肯定是编译通不过的. 除了你是在写C++而不是
: matlab, 注释应该用//而不是%以外, 这两个overloading也是不能编译的. 如果你不会
: 抄的话, 还是copy/paste来得比较容易.

1 (共1页)
进入Programming版参与讨论
相关主题
a C++ questionostream& operator << (ostream& s, int cnt) error
C++ 普及课程 (视频)1:Compiler Generated Functionsmember and friend
goodbug又丢人了一个C++语法问题
做了一个测试C++ func overload question
请问C++返回值和返回引用区别C++高手请进,内存管理问题
ambiguous operators in c++inline functions in C++
question overloading ++ errorthrust help ~~~
overload "++i"里的operator“++”,怎么declare?求题目
相关话题的讨论汇总
话题: upint话题: f1话题: c++话题: function话题: f2