📄 10.6.cpp
字号:
#include <iostream.h>
class A
{
public:
A()
{
a=0;
cout<<"Default constructor called."<<a<<endl;
}
A(int i)
{
a=i;
cout<<"Constructor callef."<<a<<endl;
}
~A()
{ cout<<"Destructor called."<<a<<endl; }
void Print()
{ cout<<a<<','; }
int Geta()
{ return a; }
private:
int a;
};
class B:public A
{
public:
B()
{
b=0;
cout<<"Default constructor called."<<b<<endl;
}
B(int i,int j,int k):A(i),aa(j)
{
b=k;
cout<<"Constructor called."<<b<<endl;
}
~B()
{ cout<<"Destructor called."<<b<<endl; }
void Print()
{
A::Print();
cout<<b<<','<<aa.Geta()<<endl;
}
private:
int b;
A aa;
};
void main()
{
B bb[2];
bb[0]=B(7,8,9);
bb[1]=B(12,13,14);
for(int i=0;i<2;i++)
bb[i].Print();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -