#include<iostream.h>
//类B的定义----------------------------------------------------------
class B
{
int i;
public:
B(int j=0):i(j){}
virtual void print(){cout<<" i= "<<i<<endl;}
void print(char *s){cout<<s<<i<<endl;}
};
//类D的定义----------------------------------------------------------
class D:public B
{
int i;
public:
D(int j=0):B(5),i(j){}
void print() {cout<< " i= "<<i<<endl;}
void print(char *s){cout<<s<<i<<endl; }
};
//函数print()的定义--------------------------------------------------
void print(B& b,char* s)
{
b.print();
b.print(s);
}
//主函数----------------------------------------------------------------
void main()
{
B b1(10);
D d1(6);
print(b1,"b1.i=");
print(d1,"d1.i=");
}
结果为:
________________
________________
________________
________________
请有条件测试的朋友帮帮忙,谢谢!