由买买提看人间百态

topics

全部话题 - 话题: upint
(共0页)
j***i
发帖数: 1278
1
来自主题: Programming版 - question overloading ++ error
I define the class UPint and overload ++ operator.
In the main function c=a++ will have a error but c=++a is fine , anybody
know the reason?
int main()
{ UPint a(1);
UPint c;
c=a++// this will produce a error
// error: no matching function for call
// to ‘UPint::UPint(const UPint)’
c=++a// fine
return 0
}
//////////////////
class UPint
{
public:
UPint(int x=0): value(x){};
UPint(UPint &rhs):value(rhs.value){};
UPint& operator=(const UPint &rhs);
UPint& op
t****t
发帖数: 6806
2
来自主题: Programming版 - question overloading ++ error
i think originally you wrote
UPint c=a++;
this tries to call UPint::UPint(const UPint&) because a++ returns a const
UPint. but you only have UPint::UPint(UPint&). so this generates an error.
c=a++ itself should be fine since you do have UPint::operator=(const UPint&).
p***o
发帖数: 1252
3
来自主题: Programming版 - question overloading ++ error
Seems a bug of gcc ...
The following code is OK with gcc (Ubuntu 4.3.3-5ubuntu4) 4.3.3
but not gcc (GCC) 3.4.5 (mingw-vista special r3). So update your
gcc first.
class UPint
{
public:
UPint();
UPint(UPint &rhs);
UPint& operator=(const UPint &rhs);
UPint operator++(int);
};
int main()
{
UPint a, c;
c=a++;
return 0;
}
G****A
发帖数: 4160
4
***************
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
5
来自主题: Programming版 - question overloading ++ error
i think the error message says all: you need a constructor with signature
UPint::UPint(const UPint&)
j***i
发帖数: 1278
6
来自主题: Programming版 - question overloading ++ error
Thanks for your explaination , it is reasonable.
however
I checked again,
I did not write UPint c a++;
actually, I define c first
it is like
UPint c;
c=a++;
it is still wrong
I using gcc in ubuntu

const
error.
UPint&).
x*******u
发帖数: 2074
7
来自主题: Programming版 - question overloading ++ error
UPint c; 这里调的是default constructor
c=a++; 这里先调你overload的++operator,然后再调assignment operator, which tak
e 前面++ operator的返回值作为参数
你的问题跟++ operator无关, 真正原因前面thrust以及compiler的error msg讲得很清
楚了, 是你没有一个take const UPint的assignment operator(or constructor)
某些compiler通得过我觉得是因为它们提供了const UPint的constructor
t****t
发帖数: 6806
8
来自主题: Programming版 - question overloading ++ error
because a++ returns const UPint, but (a) is UPint&
your copy constructor only accepts non-const version, which is obviously
wrong. in summary, you didn't add const wherever you can, so you can not use
your class as convenient as built-in types.
VC? forget it, that's not c++.
G****A
发帖数: 4160
9
这个问题是朋友问我的,所以我也没有source.
但让我confuse的部分是:
如果有一个member function: UPInt& operator++();
那么对于 UPInt A; A++; ++A; which one is a valid call to the member function?
谢谢大牛耐心解释.
L*****s
发帖数: 6046
10
http://www.douban.com/note/246591116/
猜想,反例及随感
2012-11-11 20:04:32
我大概算是后知后觉了。看了今天南都的报道,我才知道韶关学院的本科生王骁威解
决了一个“数论难题”,将发表在明年的Journal of Number Theory上。
Venecia Wang A counterexample to the prime conjecture of expressing numbers
using just ones
之前围绕刘路证明Seetapun猜想并获聘为国内最年轻的正教授级研究员一事有很多争论
。我没有参与,因为我不了解Ramsey问题,也不懂数理逻辑。不过,对于数论,我还有
一点把握。王骁威解决的问题出自Guy的Unsolved Problems in Number Theory,我知
道这本书(中学的时候翻过),也知道里面有大量零碎的小问题。略一检索,就找到了王
骁威解决的F26。
王骁威指出对于素数p = 353942783,f(p) = 1 + f(p-1) 不成立。他找到反例的方法
是简单的初等估计加上计算... 阅读全帖
x********i
发帖数: 905
11
【 以下文字转载自 Military 讨论区 】
发信人: Lwangls (老王老师), 信区: Military
标 题: 大学生破解的数论问题原来早有人解决了
发信站: BBS 未名空间站 (Mon Nov 12 20:05:20 2012, 美东)
http://www.douban.com/note/246591116/
猜想,反例及随感
2012-11-11 20:04:32
我大概算是后知后觉了。看了今天南都的报道,我才知道韶关学院的本科生王骁威解
决了一个“数论难题”,将发表在明年的Journal of Number Theory上。
Venecia Wang A counterexample to the prime conjecture of expressing numbers
using just ones
之前围绕刘路证明Seetapun猜想并获聘为国内最年轻的正教授级研究员一事有很多争论
。我没有参与,因为我不了解Ramsey问题,也不懂数理逻辑。不过,对于数论,我还有
一点把握。王骁威解决的问题出自Guy的Unsolved Problems in Num... 阅读全帖
(共0页)