由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++ Q09: delete dynamic array
相关主题
C++ Q20: construction and inheritanceprotected class member in C++
one question about structabout struct and class in c++
C++菜鸟问题请教: class versus structure.请问C++小白问题
The C++ questions I've been askedC++ Q96: function inheritance (转载)
不明白C++的一个地方What is the difference between class and struct?
one more interview question定义linked list最后一行什么意思?
C & C++ mixing questionWhy oop is bad?
两个看来相似的问题g++ problem!!!!
相关话题的讨论汇总
话题: c++话题: undefined话题: delete话题: struct话题: invokes
进入Programming版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
struct X {
virtual ~X() {}
};
class Y : public X {};
int main()
{
X* p = new Y[2];
delete[] p;
return 0;
}
What, if anything, is an error with the sample code above?
a) A "class" cannot inherit from a "struct."
b) It invokes undefined behavior.
c) "Y" requires a destructor.
d) Nothing is wrong.
E*U
发帖数: 2028
2
d

【在 c**********e 的大作中提到】
: struct X {
: virtual ~X() {}
: };
: class Y : public X {};
: int main()
: {
: X* p = new Y[2];
: delete[] p;
: return 0;
: }

d****p
发帖数: 685
3
It is b.

【在 c**********e 的大作中提到】
: struct X {
: virtual ~X() {}
: };
: class Y : public X {};
: int main()
: {
: X* p = new Y[2];
: delete[] p;
: return 0;
: }

r****t
发帖数: 10904
4
zkss?

【在 d****p 的大作中提到】
: It is b.
t****t
发帖数: 6806
5
short answer: polymorphism and array do not mix.
long answer: read effective c++.

【在 r****t 的大作中提到】
: zkss?
c**********e
发帖数: 2007
6
thrust is right.
b) It invokes undefined behavior.
This is correct. When deleting an array, the dynamic and the static type of
the object must be the same, or the behavior is undefined (C++ Standard 5.3
.5/3).

【在 t****t 的大作中提到】
: short answer: polymorphism and array do not mix.
: long answer: read effective c++.

1 (共1页)
进入Programming版参与讨论
相关主题
g++ problem!!!!不明白C++的一个地方
Three C/C++ Programming Questionsone more interview question
[转载] 问一个C++下计时的问题C & C++ mixing question
菜鸟读C++ STL源程序的疑问两个看来相似的问题
C++ Q20: construction and inheritanceprotected class member in C++
one question about structabout struct and class in c++
C++菜鸟问题请教: class versus structure.请问C++小白问题
The C++ questions I've been askedC++ Q96: function inheritance (转载)
相关话题的讨论汇总
话题: c++话题: undefined话题: delete话题: struct话题: invokes