#include<iostream.h>
class base
{
public:
base(){a=0;}
base(int i){a=i;}
void print(){cout<<"a="<<a<<endl;}
int geta(){return a;}
private:
int a;
};
class derived:public base
{
public:
derived(){b=0;}
derived(int i,int j): base(i),b(j){}
void print()
{
base::print();
cout<<"b="<<b<<endl;
}
private:
int b;
};
void func(base& bb)
{
cout<<bb.geta()*10<<endl;
}
int main(void)
{
derived obj2(9,5);
base obj1(5);
obj1=obj2;
obj1.print();
base *pbase=new base(8);
derived *pderived=new derived(1,2);
pbase=pderived;
pbase->print();
func(obj2);
return 0;
}
我想问下
derived(int i,int j): base(i),b(j){}
这句代码什么意思?b(j){}在这做什么用?