由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - pointer to base class = new derived, what will happend??
相关主题
find bugs of c++ codes回答C++的弱问题
a c++ question[合集] C++的弱问题
我这个C++程序有没有什么问题啊?请指点。。。谢谢。。。What does the default constructor do?
一道c++的考古题class with a pointer member
急问:compile and build dependency请问delete的问题
C++的一个小疑问,求解惑c++ dynamic cast
请教一个c++ throw exception 问题template 类的继承问题
C++ virtual function 定义在 derived class 会怎么样?请教C++问题
相关话题的讨论汇总
话题: derived话题: base话题: class话题: happend话题: new
进入Programming版参与讨论
1 (共1页)
v*****r
发帖数: 2325
1
class base{ base() {}; ~base() {};};
class derived : base { derived() {}; ~derived() {};);
base* ptr = new derived;
explain what will happen
my guess is that:
with out specify virtual function, even through the derived class object is
allocated, but ptr will use base class members… if there is no virtual
function declared in base class.
right?
z****n
发帖数: 1379
2
只有析构函数是这样吧?
构造函数还是两个都调用的吧

is

【在 v*****r 的大作中提到】
: class base{ base() {}; ~base() {};};
: class derived : base { derived() {}; ~derived() {};);
: base* ptr = new derived;
: explain what will happen
: my guess is that:
: with out specify virtual function, even through the derived class object is
: allocated, but ptr will use base class members… if there is no virtual
: function declared in base class.
: right?

z****e
发帖数: 2024
3
你这个肯定错误,私有继承,另外还私有ctor,一团浆糊。
v*****r
发帖数: 2325
4
yes. without explicity specify "access specifier ", it is
class derived: private base {
}
Although the constructors and destructors of the base class are not
inherited themselves, its default constructor (i.e., its constructor with no
parameters) and its destructor are always called when a new object of a
derived class is created or destroyed.

【在 z****e 的大作中提到】
: 你这个肯定错误,私有继承,另外还私有ctor,一团浆糊。
B*******g
发帖数: 1593
5
把两个class的 ctor dtor 去掉这题就有点意思了

is

【在 v*****r 的大作中提到】
: class base{ base() {}; ~base() {};};
: class derived : base { derived() {}; ~derived() {};);
: base* ptr = new derived;
: explain what will happen
: my guess is that:
: with out specify virtual function, even through the derived class object is
: allocated, but ptr will use base class members… if there is no virtual
: function declared in base class.
: right?

1 (共1页)
进入Programming版参与讨论
相关主题
请教C++问题急问:compile and build dependency
C++问题C++的一个小疑问,求解惑
用包子呼唤大牛们--问关于C++Destructor的问题请教一个c++ throw exception 问题
C++ online Test 2题C++ virtual function 定义在 derived class 会怎么样?
find bugs of c++ codes回答C++的弱问题
a c++ question[合集] C++的弱问题
我这个C++程序有没有什么问题啊?请指点。。。谢谢。。。What does the default constructor do?
一道c++的考古题class with a pointer member
相关话题的讨论汇总
话题: derived话题: base话题: class话题: happend话题: new