大家帮忙,读一下程序,谢谢
本人初学C++,不太懂,有两个小程序就读懂,请高手帮忙读一下,最好能给出输出结果和讲解一下!谢谢!1、
#include<iostream.h>
class A
{public: A(){cout<<"A";}
~A(){cout<<"~A";}};
class B: public A
{public: B(){cout<<"B";}
~B(){cout<<"~B";}
};
class c:public B
{public: c(){cout<<"c";}
~C(){cout<<"~C";}
private: Am; Bn;
};
A obj;
int main()
{ C*P=new C; cout<<endl;
B obj; cout<<endl;
delete P; cout<<endl;
return 0;
}
2、
#include<iostream.h>
class A {public: virtual void output() {cout<<"class A\n";}};
class B:public A {viod output() {cout<<"class B\n";}};
class C:public A {void output() {cout<<"class C\n";}};
class D:public C { Cm;};
class E:public B{void output() {cout<<"class E\n";} Bm;};
int main()
{ Aa;Bb;Cc;Dd;Ee;
A*P[]={&a,&b,&c,&d,&e};
A v[]={a,b,c,d,e};
for (int i=0;i<5;i++) {P[ i ] ->output();v[ i ].output();}
return 0;
}