由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 还是咱们这儿,亲。
相关主题
请问C++中局部未使用的变量在优化的时候会去掉么?问个c++的弱问题
大侠们救命, C++ operator new 问题C++菜问: 怎么这样也可以?
一个读用户输入的小问题why use static function here?
定义的struct数组很大时,为什么会出现奇怪的大数字?Use Visual .NET for C++ programming
int i:1三个C syntax 弱问题
为什么foo1可以而foo2不行?这个C++程序为什么不能运行
菜鸟求教,一个c++的困惑a question on C++ string
请教这个程序里用到了什么constructor啊?有几个copy constructor?A aimple C++ question
相关话题的讨论汇总
话题: operator话题: int话题: std话题: value话题: val
进入Programming版参与讨论
1 (共1页)
z****e
发帖数: 2024
1
在找工版看得,我做了作,也有不确定的2个。大侠有空玩玩吧,
有一些C++的题目, 不是很sure,请大家来做做.
1. class Value{
std::string s_val;
int i_val;
public:
Value(std::string s, int i): s_val(s),i_val(i){}
};
Referring to the sample code above, which one of the following operators
do you need to override in order to be able to use the container
"std::set"?
A. operator >
B. operator >=
C. operator !=
D. operator <=
E. operator <
my answer: E
2.
void HandleNoMemory();
int _tmain(int argc, _TCHAR* argv[])
{
z****e
发帖数: 2024
2
以上答案都是我第一遍做得。
d****p
发帖数: 685
3
Nice.
7's answer is E.
X****r
发帖数: 3557
4
2. should be A. Implementation-provided operator new throws
std::bad_alloc instead of returning null when there is not enough
memory. Use new (std::nothrow) int[100] to prevent throwing
the exception.

【在 z****e 的大作中提到】
: 在找工版看得,我做了作,也有不确定的2个。大侠有空玩玩吧,
: 有一些C++的题目, 不是很sure,请大家来做做.
: 1. class Value{
: std::string s_val;
: int i_val;
: public:
: Value(std::string s, int i): s_val(s),i_val(i){}
: };
: Referring to the sample code above, which one of the following operators
: do you need to override in order to be able to use the container

X****r
发帖数: 3557
5
4. D.

【在 z****e 的大作中提到】
: 在找工版看得,我做了作,也有不确定的2个。大侠有空玩玩吧,
: 有一些C++的题目, 不是很sure,请大家来做做.
: 1. class Value{
: std::string s_val;
: int i_val;
: public:
: Value(std::string s, int i): s_val(s),i_val(i){}
: };
: Referring to the sample code above, which one of the following operators
: do you need to override in order to be able to use the container

X****r
发帖数: 3557
6
ft, so long... didn't finish it.

【在 z****e 的大作中提到】
: 在找工版看得,我做了作,也有不确定的2个。大侠有空玩玩吧,
: 有一些C++的题目, 不是很sure,请大家来做做.
: 1. class Value{
: std::string s_val;
: int i_val;
: public:
: Value(std::string s, int i): s_val(s),i_val(i){}
: };
: Referring to the sample code above, which one of the following operators
: do you need to override in order to be able to use the container

z****e
发帖数: 2024
7
是的,很长。
4 什么意思呢?
版主给说说吧。

【在 X****r 的大作中提到】
: ft, so long... didn't finish it.
z****e
发帖数: 2024
8
的确。
感谢。

【在 d****p 的大作中提到】
: Nice.
: 7's answer is E.

S*********g
发帖数: 5298
9
this is test problems from brainbench?

【在 z****e 的大作中提到】
: 在找工版看得,我做了作,也有不确定的2个。大侠有空玩玩吧,
: 有一些C++的题目, 不是很sure,请大家来做做.
: 1. class Value{
: std::string s_val;
: int i_val;
: public:
: Value(std::string s, int i): s_val(s),i_val(i){}
: };
: Referring to the sample code above, which one of the following operators
: do you need to override in order to be able to use the container

z****e
发帖数: 2024
10
我也不知道。

【在 S*********g 的大作中提到】
: this is test problems from brainbench?
相关主题
为什么foo1可以而foo2不行?问个c++的弱问题
菜鸟求教,一个c++的困惑C++菜问: 怎么这样也可以?
请教这个程序里用到了什么constructor啊?有几个copy constructor?why use static function here?
进入Programming版参与讨论
z****e
发帖数: 2024
11
可是编译通不过呀。
那个函数没有给定义,只有声明。
你看得更深,我觉得你也是对的。是不会被调用的,因为if 为真的时候,就throw了。
但是编译也通不过呀。为什么不能选编译通不过呢?
也许题目抄错了吧。我不是题目源,所以就这样理解了吧。

【在 X****r 的大作中提到】
: 2. should be A. Implementation-provided operator new throws
: std::bad_alloc instead of returning null when there is not enough
: memory. Use new (std::nothrow) int[100] to prevent throwing
: the exception.

l******e
发帖数: 12192
12
封装

【在 z****e 的大作中提到】
: 是的,很长。
: 4 什么意思呢?
: 版主给说说吧。

d****p
发帖数: 685
13
I think the program doesn't compile so thinking pig made a mistake, a
mistake only expert makes :-)

【在 z****e 的大作中提到】
: 可是编译通不过呀。
: 那个函数没有给定义,只有声明。
: 你看得更深,我觉得你也是对的。是不会被调用的,因为if 为真的时候,就throw了。
: 但是编译也通不过呀。为什么不能选编译通不过呢?
: 也许题目抄错了吧。我不是题目源,所以就这样理解了吧。

t****t
发帖数: 6806
14
1 E
2 A (well D is also right since getchar is not recognized...)
3 B
4 D
5 C
6 B
7 E
8 E
9 D (actually it's not strictly correct: you may call Account::get_name() if
you define it. Yes you can define a pure virtual function. Although in this
case, it's probably not what you want, since in dtor, it will not call
overrided get_name().)
10 A (but I think E is also correct. In fact, A::getBaseNum HIDES Base::
getBaseNum, and A::baseNum HIDES Base::baseNum (which is private anyway).)
11 A
12 E
13 C
z****e
发帖数: 2024
15
10.E说的是overloading,但是茴香豆的茴字写法是说:
overload 是同一个类自己内部的事情。
如果子类重新定义,分为两种情况,
1.redefine: if base member fun version not virtual
2.override: if base mem fun is virtual.
没有overload的事。name hiding 是以上这两种情况。
本题应该属于第一类,就是redefine.
这个是小人的一点粗浅理解。
你想也是,overload本身就是体现同名而不同功能,不会hide name。所以overload和namehide还是不同的。namehide是不同namespace的事情,overload是同一个namespace的事情。
这个是小人的一点很不成熟的想法。

if
this

【在 t****t 的大作中提到】
: 1 E
: 2 A (well D is also right since getchar is not recognized...)
: 3 B
: 4 D
: 5 C
: 6 B
: 7 E
: 8 E
: 9 D (actually it's not strictly correct: you may call Account::get_name() if
: you define it. Yes you can define a pure virtual function. Although in this

z****e
发帖数: 2024
16
还是要感谢大侠百忙之中莅临指导。
以及其他回帖诸公。一一拜谢。

if
this

【在 t****t 的大作中提到】
: 1 E
: 2 A (well D is also right since getchar is not recognized...)
: 3 B
: 4 D
: 5 C
: 6 B
: 7 E
: 8 E
: 9 D (actually it's not strictly correct: you may call Account::get_name() if
: you define it. Yes you can define a pure virtual function. Although in this

z****e
发帖数: 2024
17
第16题我错了。
你应该是对的。
basic_streambuf 是类型,是type name,
但是题目问的是typedef name,应该是没有了模板参数的。

if
this

【在 t****t 的大作中提到】
: 1 E
: 2 A (well D is also right since getchar is not recognized...)
: 3 B
: 4 D
: 5 C
: 6 B
: 7 E
: 8 E
: 9 D (actually it's not strictly correct: you may call Account::get_name() if
: you define it. Yes you can define a pure virtual function. Although in this

z****e
发帖数: 2024
18
A,D就都是对的吧。

【在 d****p 的大作中提到】
: I think the program doesn't compile so thinking pig made a mistake, a
: mistake only expert makes :-)

z****e
发帖数: 2024
19
9,我同意你说得。原因不是因为在dtr里边,也不是因为是pure virtual,原因是因为
一个没有定义的pure virtual。定义了,就可以调。但是dtr里边只能调local版本。

if
this

【在 t****t 的大作中提到】
: 1 E
: 2 A (well D is also right since getchar is not recognized...)
: 3 B
: 4 D
: 5 C
: 6 B
: 7 E
: 8 E
: 9 D (actually it's not strictly correct: you may call Account::get_name() if
: you define it. Yes you can define a pure virtual function. Although in this

r****y
发帖数: 87
20
哪位大侠麻烦解释一下第7题,谢了
相关主题
Use Visual .NET for C++ programminga question on C++ string
三个C syntax 弱问题A aimple C++ question
这个C++程序为什么不能运行C++ 初级再初级问题
进入Programming版参与讨论
N***m
发帖数: 4460
21
Is it bool std::operator == (char*,std::string) ?
哈哈,好久不见C++,都差不多忘光了。

【在 r****y 的大作中提到】
: 哪位大侠麻烦解释一下第7题,谢了
h*******s
发帖数: 8454
22
en 比较的这些operator都是global的
bool operator== ( const string& lhs, const string& rhs );
bool operator== ( const char* lhs, const string& rhs );
bool operator== ( const string& lhs, const char* rhs );

【在 N***m 的大作中提到】
: Is it bool std::operator == (char*,std::string) ?
: 哈哈,好久不见C++,都差不多忘光了。

r****y
发帖数: 87
23
多谢楼上2位大侠,7题我明白了。
再麻烦问一下12题,E是干什么呢?
要cout< 哪位大侠赐教,我先谢过了。
N***m
发帖数: 4460
24
you can do it in person's friend function,
or you can do it as in E. The compiler will try the conversion and
find the best match which is E in this case.

【在 r****y 的大作中提到】
: 多谢楼上2位大侠,7题我明白了。
: 再麻烦问一下12题,E是干什么呢?
: 要cout<: 哪位大侠赐教,我先谢过了。

r****y
发帖数: 87
25
多谢楼上大侠,12题我也明白了。
对第8题我还有点疑问,如果选e, 那int& function() 里面一定create 了一个int (
no matter static or not),然后return 那个int的reference。然后function()=x,
把这个reference 重新指向了另一个int x.
可是,once a reference is initialized to an object, it cannot be changed to
refer to another object.
虽然那样做会compile,可是与rules of using reference 矛盾啊。。。
请指教,谢谢。

【在 N***m 的大作中提到】
: you can do it in person's friend function,
: or you can do it as in E. The compiler will try the conversion and
: find the best match which is E in this case.

t****t
发帖数: 6806
26
in "function()=x;", = is really assignment operator (as in "a=5;", not
initialization (as in "int& a=b;"). so it's assigning x to the returned
reference, not "refering again" the reference.
PS: the function() doesn't have to "create" an int. it creates a reference
to int, that's all you can say.

to

【在 r****y 的大作中提到】
: 多谢楼上大侠,12题我也明白了。
: 对第8题我还有点疑问,如果选e, 那int& function() 里面一定create 了一个int (
: no matter static or not),然后return 那个int的reference。然后function()=x,
: 把这个reference 重新指向了另一个int x.
: 可是,once a reference is initialized to an object, it cannot be changed to
: refer to another object.
: 虽然那样做会compile,可是与rules of using reference 矛盾啊。。。
: 请指教,谢谢。

c**b
发帖数: 2999
27
en
==成了helper operator in global space

【在 h*******s 的大作中提到】
: en 比较的这些operator都是global的
: bool operator== ( const string& lhs, const string& rhs );
: bool operator== ( const char* lhs, const string& rhs );
: bool operator== ( const string& lhs, const char* rhs );

1 (共1页)
进入Programming版参与讨论
相关主题
A aimple C++ questionint i:1
C++ 初级再初级问题为什么foo1可以而foo2不行?
A helloworld OpenMP question?菜鸟求教,一个c++的困惑
请教C++问题请教这个程序里用到了什么constructor啊?有几个copy constructor?
请问C++中局部未使用的变量在优化的时候会去掉么?问个c++的弱问题
大侠们救命, C++ operator new 问题C++菜问: 怎么这样也可以?
一个读用户输入的小问题why use static function here?
定义的struct数组很大时,为什么会出现奇怪的大数字?Use Visual .NET for C++ programming
相关话题的讨论汇总
话题: operator话题: int话题: std话题: value话题: val