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?
|