#include<iostream>
using namespace std;
class Base {
private:
int b;
public:
Base(int bvalue=0) {
b = bvalue;
cout << "B's ctor" << endl;
}
~Base() { }
};
class Derv : public Base {
public:
int d;
Derv(int bval, int dval) : Base(bval),d(dval) {
cout << "D's ctor" << endl;
}
Derv(int dval) : d(dval) {
cout << "D's ctor " << endl;
}
};
int main(){
Derv D1(4,5);
Derv D2(100);
return 0;
}
上述程序编译罚款,我看到输出作为继承和私有成员
B's ctor
D's ctor
B's ctor
D's ctor
由于基类的私有成员不继承,什么是内存位置基本构造是创建私有会员在?
注意:这个问题包含一个误解,这是完全解决了答案。
谢谢,这澄清了我的疑问。非常感谢。 – irappa 2011-05-29 17:28:13
+1:但不能保证'b'和'd'将**相邻** – 6502 2011-05-29 17:44:54
@ 6502:True;我细化了我的答案。 +1。 – 2011-05-29 17:47:15