首页 新闻 会员 周边

新手求解,子对象可以输出吗?如何输出?代码如下:

0
悬赏园豆:5 [已关闭问题] 关闭于 2016-05-03 13:17
#include<iostream>
using namespace std;
class B
{
public:
    B(int i) {
        x = i;
        cout << "Constructor of B" << endl;
    }
    ~B()
    {
        cout << "Destructor of B" << endl;
    }
    void show()
    {
        cout << "x=" << x << endl;
    }
private:
    int x;
};
class D :public B
{
public :
    D(int i, int j, int k) :B(j), d(k)
    {
        cout << "Constructor of D" << endl;
    }
    ~D()
    {
        cout << "Destructor of D" << endl;
    }
    void show1()
    {
        cout << "d=" <<endl;
    }
private:
    B d;
};
int main()
{
    D obj(4, 5, 6);
    obj.show();
    return 0;
}
爱是用心码不要说话的主页 爱是用心码不要说话 | 初学一级 | 园豆:154
提问于:2016-04-03 09:17
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册