首页 > 试题广场 >

阅读该程序,给出程序的输出结果。

[问答题]

阅读该程序,给出程序的输出结果。

#include <iostream.h>

class A

{

public:

    A(int i,int j)

    {

        a1=i;

        a2=j;

    }

    void Print()

    {

        cout<<a1<<','<<a2<<endl;

    }

private:

    int a1,a2;

};

class B

{

public:

    B() : b(0)

    {

    }

    B(int i) : b(i)

    {

    }

    void Print()

    {

        cout<<b<<endl;

    }

private:

    int b;

};

class C: public A

{

    public:

    C(int i,int j,int k,int l):A(i,j),c(l)

    {

    }

    void Print()

    {

        A::Print();

        b.Print();

        cout<<c<<endl;

    }

private:

    B b;

    int c;

};

void main()

{

    A a(7,8);

    a.Print();

    B b(9);

    b.Print();

    C c(4,5,6,7);

    c.Print();

}
7,8
9
4,5,
0
7

C类中的私有成员B b调用的是默认构造函数吧

发表于 2020-12-21 21:12:10 回复(0)