U*********y 发帖数: 54 | 1 class A *a = new A();
vs.
class A *a = new A;
请教initialization和exception时的区别 |
a********n 发帖数: 1287 | |
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 | |
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时的区别
|
|
|
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时的区别
|