由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - bloomberg 问题: C++ construct 时用 new 没"()"
相关主题
问一个constructor的问题C++ Q68: initialization (skillport)
问一个C++ set和unordered_set iterator的问题问一个c++问题关于reference vs. pointer
C++定义数组长度可以写成int a[n]吗?问道G题(2)
C++相关的面经发几个C++面试题,senior的职位
static initialization dependency c++ (转载)A question about C++. Thanks.
问个debug和release mode的问题H1B TRANSFER 都快7个月了,还在Initial Review , 郁闷
攒rp,电面题目大家看看这个题目改怎么做。
有面过knight的吗Amazon电面 (05/02/09更新第二次,第三次电面)
相关话题的讨论汇总
话题: new话题: c++话题: difference话题: exception话题: class
进入JobHunting版参与讨论
1 (共1页)
U*********y
发帖数: 54
1
class A *a = new A();
vs.
class A *a = new A;
请教initialization和exception时的区别
a********n
发帖数: 1287
2
感觉没区别。
d********t
发帖数: 9628
3
以前听人说对built in的type才有区别。不过对exeption有啥影响我就不知道了。

【在 a********n 的大作中提到】
: 感觉没区别。
w********0
发帖数: 377
4
“exception时”是什么意思?不好意思,水平比较菜。想学习一下。 谢谢

【在 U*********y 的大作中提到】
: class A *a = new A();
: vs.
: class A *a = new A;
: 请教initialization和exception时的区别

m*******l
发帖数: 12782
5
what the definition of A?

【在 U*********y 的大作中提到】
: class A *a = new A();
: vs.
: class A *a = new A;
: 请教initialization和exception时的区别

m*******l
发帖数: 12782
6
异常
异常处理.

【在 w********0 的大作中提到】
: “exception时”是什么意思?不好意思,水平比较菜。想学习一下。 谢谢
m*******l
发帖数: 12782
7
忘了要包子

【在 m*******l 的大作中提到】
: 异常
: 异常处理.

B******5
发帖数: 4676
8
求解
A 和 A()的区别。。
S**I
发帖数: 15689
9
For initialization, the difference depends on A's definition.
I don't think there is any difference for exception (except for exceptions
caused by initialization difference).

【在 U*********y 的大作中提到】
: class A *a = new A();
: vs.
: class A *a = new A;
: 请教initialization和exception时的区别

r****t
发帖数: 10904
10
POD value initiation. exception 区别不知道了
请问是 bloomberg 哪个位置阿?

【在 U*********y 的大作中提到】
: class A *a = new A();
: vs.
: class A *a = new A;
: 请教initialization和exception时的区别

相关主题
问个debug和release mode的问题C++ Q68: initialization (skillport)
攒rp,电面题目问一个c++问题关于reference vs. pointer
有面过knight的吗问道G题(2)
进入JobHunting版参与讨论
U*********y
发帖数: 54
11
software dev

【在 r****t 的大作中提到】
: POD value initiation. exception 区别不知道了
: 请问是 bloomberg 哪个位置阿?

U*********y
发帖数: 54
12
此题是一道online assessment的多选题. 排除不正确的选项后,剩下的选项说:
class A *a = new A(); 会扔 bad_alloc 并 return null ; class A *a = new A 不
会这样...求证实
M****g
发帖数: 162
13
The difference between new A and new A() is that the former is uninitialized
and the later one will be default initialized.
y*******g
发帖数: 6599
14
开什么玩笑?

uninitialized

【在 M****g 的大作中提到】
: The difference between new A and new A() is that the former is uninitialized
: and the later one will be default initialized.

y*******g
发帖数: 6599
15
扔 bad_alloc 并 return null
错,扔了bad_alloc就不会有返回值了。
其他选项有问题吧?

【在 U*********y 的大作中提到】
: 此题是一道online assessment的多选题. 排除不正确的选项后,剩下的选项说:
: class A *a = new A(); 会扔 bad_alloc 并 return null ; class A *a = new A 不
: 会这样...求证实

h*c
发帖数: 1859
16
u r right.
if bad_alloc throws,
no return
maybe call abort () directly if not handled

【在 y*******g 的大作中提到】
: 扔 bad_alloc 并 return null
: 错,扔了bad_alloc就不会有返回值了。
: 其他选项有问题吧?

S**I
发帖数: 15689
17
In C++98, new A() is default-initialized; in C++03 and C++11, new A() is
value-initialized.

uninitialized

【在 M****g 的大作中提到】
: The difference between new A and new A() is that the former is uninitialized
: and the later one will be default initialized.

h*c
发帖数: 1859
18
true

【在 S**I 的大作中提到】
: In C++98, new A() is default-initialized; in C++03 and C++11, new A() is
: value-initialized.
:
: uninitialized

l****c
发帖数: 838
19
You can write a simple test case, cannot you?
my test shows no difference:
=========================================
#include
using namespace std;
class A {
public:
A() {
cout<<"ctr"<< endl;
throw 1;
}
~A() {
cout <<"dstr"<< endl;
}
};
int main()
{
A* pa = new A;
delete pa;

return 0;
}
==========================
Both terminated.

【在 U*********y 的大作中提到】
: 此题是一道online assessment的多选题. 排除不正确的选项后,剩下的选项说:
: class A *a = new A(); 会扔 bad_alloc 并 return null ; class A *a = new A 不
: 会这样...求证实

h*c
发帖数: 1859
20
delete destructor and test again

【在 l****c 的大作中提到】
: You can write a simple test case, cannot you?
: my test shows no difference:
: =========================================
: #include
: using namespace std;
: class A {
: public:
: A() {
: cout<<"ctr"<< endl;
: throw 1;

l****c
发帖数: 838
21
If ctr throws exception, dtr will not be called at all.

【在 h*c 的大作中提到】
: delete destructor and test again
A**u
发帖数: 2458
22
int 有区别
new int 没有调用 ctor
自定义 class 没区别

【在 U*********y 的大作中提到】
: class A *a = new A();
: vs.
: class A *a = new A;
: 请教initialization和exception时的区别

1 (共1页)
进入JobHunting版参与讨论
相关主题
Amazon电面 (05/02/09更新第二次,第三次电面)static initialization dependency c++ (转载)
[合集] 贡献几个C/C++编程电话面试题问个debug和release mode的问题
如何准备bloomberg online test攒rp,电面题目
一个电面有面过knight的吗
问一个constructor的问题C++ Q68: initialization (skillport)
问一个C++ set和unordered_set iterator的问题问一个c++问题关于reference vs. pointer
C++定义数组长度可以写成int a[n]吗?问道G题(2)
C++相关的面经发几个C++面试题,senior的职位
相关话题的讨论汇总
话题: new话题: c++话题: difference话题: exception话题: class