由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++ Q02:
相关主题
stl Compare为何需要重载()?C++ delete
c++ operator overloading question关于placement new
C++命名空间和算子重载大侠们救命, C++ operator new 问题
针对class的成员变量的operator能重载吗?求教new delete 在c++中的重载
C++: &*var是啥意思?容器里边放指针怎么办?
C++糟粕和需要避免的。c++ 如何重用一段代码,并把其中加法变成减法
用STL map的时候怎么自己定义大小比较的关系为什么不能成功排序
一个C++ operator new的重载问题重载 ^ 操作符编译出错
相关话题的讨论汇总
话题: int话题: coord话题: c++话题: operator话题: overloaded
进入Programming版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
class coord {
int x, y;
public:
coord(int i, int j) {x=i; y=j;}
operator int() { return x*y; }
};
int main() {
coord o1(2,3);
int i, j;
i=o1;
j=5;
return 0;
}
a. There is an error because coord does not have an overloaded assignment
operator that returns an int.
b. There is an error because coord does not have an overloaded assignment
operator that returns an int.
c. The final value of i will be 6.
d. There is an error because the overloaded operator must have a return type
.
I*****y
发帖数: 602
2
c

【在 c**********e 的大作中提到】
: class coord {
: int x, y;
: public:
: coord(int i, int j) {x=i; y=j;}
: operator int() { return x*y; }
: };
: int main() {
: coord o1(2,3);
: int i, j;
: i=o1;

v*****r
发帖数: 2325
3
it is User-defined conversions in C++, but can use a more understandable
member function.
c++ is strong type language, why allow this?

【在 I*****y 的大作中提到】
: c
d*****d
发帖数: 46
4
Agree, implicit conversion is an evil in general. An "explicit" keyword is
considering by c++...

【在 v*****r 的大作中提到】
: it is User-defined conversions in C++, but can use a more understandable
: member function.
: c++ is strong type language, why allow this?

c**********e
发帖数: 2007
5
Hehe, this is to test basic C++ knowledge.

【在 v*****r 的大作中提到】
: it is User-defined conversions in C++, but can use a more understandable
: member function.
: c++ is strong type language, why allow this?

v*****r
发帖数: 2325
6
frankly, 边边角角 knowledge. But yes if somebody knows about this without
much preparation, then his vocabulary of C++ language is huge. but his problem solving skills, algorithm design skills are not tested....
which company or what kind of company tests u about this?

【在 c**********e 的大作中提到】
: Hehe, this is to test basic C++ knowledge.
c**********e
发帖数: 2007
7
作为低手,不得不学习茴香豆的茴字的四种写法。高手就不用了。

without
problem solving skills, algorithm design skills are not tested....

【在 v*****r 的大作中提到】
: frankly, 边边角角 knowledge. But yes if somebody knows about this without
: much preparation, then his vocabulary of C++ language is huge. but his problem solving skills, algorithm design skills are not tested....
: which company or what kind of company tests u about this?

B********e
发帖数: 1062
8
How can you expect a guy who don't know these questions to write serious C++
codes?

without
problem solving skills, algorithm design skills are not tested....

【在 v*****r 的大作中提到】
: frankly, 边边角角 knowledge. But yes if somebody knows about this without
: much preparation, then his vocabulary of C++ language is huge. but his problem solving skills, algorithm design skills are not tested....
: which company or what kind of company tests u about this?

p********7
发帖数: 549
9
能具体解释下么?我学过符号重载啊,也用过,但是真不知道为啥答案就是6呢

++

【在 B********e 的大作中提到】
: How can you expect a guy who don't know these questions to write serious C++
: codes?
:
: without
: problem solving skills, algorithm design skills are not tested....

p********7
发帖数: 549
10
能具体解释下么?我学过符号重载啊,也用过,但是真不知道为啥答案就是6呢

++

【在 B********e 的大作中提到】
: How can you expect a guy who don't know these questions to write serious C++
: codes?
:
: without
: problem solving skills, algorithm design skills are not tested....

相关主题
C++糟粕和需要避免的。C++ delete
用STL map的时候怎么自己定义大小比较的关系关于placement new
一个C++ operator new的重载问题大侠们救命, C++ operator new 问题
进入Programming版参与讨论
d*****1
发帖数: 1837
11
i = o1
=>
i = (int) o1
=> i = 2*3

【在 p********7 的大作中提到】
: 能具体解释下么?我学过符号重载啊,也用过,但是真不知道为啥答案就是6呢
:
: ++

l******9
发帖数: 7
12
I think this is functor (function object). It is discussed in ch16 of c++
primer
X****r
发帖数: 3557
13
What you think is wrong.

c++

【在 l******9 的大作中提到】
: I think this is functor (function object). It is discussed in ch16 of c++
: primer

N***m
发帖数: 4460
14
大虾帮我看看ajax小问题啊

【在 X****r 的大作中提到】
: What you think is wrong.
:
: c++

S***w
发帖数: 1014
15
不错 好题

【在 c**********e 的大作中提到】
: class coord {
: int x, y;
: public:
: coord(int i, int j) {x=i; y=j;}
: operator int() { return x*y; }
: };
: int main() {
: coord o1(2,3);
: int i, j;
: i=o1;

1 (共1页)
进入Programming版参与讨论
相关主题
重载 ^ 操作符编译出错C++: &*var是啥意思?
make 时候遇到 undefined reference 怎么办?C++糟粕和需要避免的。
C++重载<<错误?用STL map的时候怎么自己定义大小比较的关系
一个matrix类定义的问题一个C++ operator new的重载问题
stl Compare为何需要重载()?C++ delete
c++ operator overloading question关于placement new
C++命名空间和算子重载大侠们救命, C++ operator new 问题
针对class的成员变量的operator能重载吗?求教new delete 在c++中的重载
相关话题的讨论汇总
话题: int话题: coord话题: c++话题: operator话题: overloaded