输出的结果?
#include <iostream.h>class A{
private:
static int n;
int X;
public:
A(int x=0){X=x;n++;}
~A(){n--;}
static int GetNum(){return n;}
void print();
};
void A::print(){cout<<"n="<<n<<","X="<<X<<endl;}
int A::n=0;
void main()
{
A*p=new A(12);
p->print();
A a(34);
a.print();
delete p;
cout<<"n="<<A::GetNum()<<endl;
}
第二道
#include<iostream.h>
class A
{
public:
int n;
};
class B:virtual public A{};
class C:virtual public A{};
class D:public B,public C
{
int getn(){return B::n;}
};
void main()
{
D d;
d.B::n=10;
d.C::n=20;
cout<<d.B::n<<","<<d.C::n<<endl;
}
两道都是考试题,麻烦各位大侠帮帮忙了