由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - two c++ interview questions! (转载)
相关主题
一个C++语法问题[合集] C++问题(copy constructor)
a simple question for C++ class问一个简单的C++问题
请问一个exception题目一个指向指针的指针的引用?
两个继承问题问个char*的问题
为什么我看不懂下面的code,是不是水平还不够?数组弱问
C++疑问[合集] 关于构造函数
请教一个作用域的问题C++菜问: 怎么这样也可以?
compare double to floatc++之极弱问
相关话题的讨论汇总
话题: nvalue话题: int话题: public话题: questions话题: c++
进入Programming版参与讨论
1 (共1页)
x***o
发帖数: 135
1
【 以下文字转载自 JobHunting 讨论区 】
发信人: xltao (iii), 信区: JobHunting
标 题: two c++ interview questions!
发信站: BBS 未名空间站 (Wed Sep 19 15:09:11 2007)
#include
using namespace std;
class A
{
protected:
int nValue;
public:
A( int n ) : nValue( n )
{
nValue++;
}
};
class B : public A
{
public:
B( int n ) : A( n * 10 )
{
this->nValue += 50;
}
void Output()
{
cout << nValue << endl;
}
};
int main()
{
B b( 10 );
b.Output();
retu
F*****n
发帖数: 1552
2
What Why?
What's the questions?
x***o
发帖数: 135
3
The answer is
1) 151.
2) 2 1 0
I mean why the answer is 151 for code1, 2 1 0 for code2.

【在 x***o 的大作中提到】
: 【 以下文字转载自 JobHunting 讨论区 】
: 发信人: xltao (iii), 信区: JobHunting
: 标 题: two c++ interview questions!
: 发信站: BBS 未名空间站 (Wed Sep 19 15:09:11 2007)
: #include
: using namespace std;
: class A
: {
: protected:
: int nValue;

X****r
发帖数: 3557
4
2) is wrong, strictly speaking.
From the Holy Standard:
5.2.2 Function call
8. The order of evaluation of arguments is unspecified.

【在 x***o 的大作中提到】
: The answer is
: 1) 151.
: 2) 2 1 0
: I mean why the answer is 151 for code1, 2 1 0 for code2.

s******u
发帖数: 247
5
8. The order of evaluation of arguments is unspecified.
但是为什么运行结果都是2,1,0,而不是别的呢?谢谢
y*w
发帖数: 238
6
全看今天compiler ha不happy了

【在 s******u 的大作中提到】
: 8. The order of evaluation of arguments is unspecified.
: 但是为什么运行结果都是2,1,0,而不是别的呢?谢谢

t****t
发帖数: 6806
7
"都"是2,1,0?你这个“都”是哪里来的?你试过几个编译器?试过几个平台?

【在 s******u 的大作中提到】
: 8. The order of evaluation of arguments is unspecified.
: 但是为什么运行结果都是2,1,0,而不是别的呢?谢谢

k****f
发帖数: 3794
8
一台机器运行10遍. :)

【在 t****t 的大作中提到】
: "都"是2,1,0?你这个“都”是哪里来的?你试过几个编译器?试过几个平台?
1 (共1页)
进入Programming版参与讨论
相关主题
c++之极弱问为什么我看不懂下面的code,是不是水平还不够?
请教一个c++ reference问题C++疑问
请教一道入门小题请教一个作用域的问题
大家来做题C++。compare double to float
一个C++语法问题[合集] C++问题(copy constructor)
a simple question for C++ class问一个简单的C++问题
请问一个exception题目一个指向指针的指针的引用?
两个继承问题问个char*的问题
相关话题的讨论汇总
话题: nvalue话题: int话题: public话题: questions话题: c++