没注释的源代码
#include <iostream>
#include <string>
using namespace std;
class Animal
{
public:
Animal(int a,double w):age(a),weight(w){cout<<"Constructor in Animal."<<endl;}
~Animal(){cout<<"Constructor in Animal."<<endl;}
void display()
{
cout<<"age:"<<age<<endl;
cout<<"weight:"<<weight<<endl;
}
private:
int age;
double weight;
};
class Dog:public Animal
{
public:
Dog(int a,double w,string col):Animal(a,w),color(col){cout<<"Constructor in Dog."<<endl;}
~Dog(){cout<<"Constructor in Dog."<<endl;}
void display1()
{
display();
cout<<"color:"<<color<<endl;
}
private:
string color;
};
int main()
{
Dog d(5,10,"白色");
d.display1();
return 0;
}