主题:实现 观察基类与派生类的构造函数与析构函数的调用顺序。!!!
[size=5]#include <iostream.h>
class mammal
{
public:
mammal(){};
void print()
{
cout<<"基类的构造函数出现了"<<endl;
}
~mammal(){};
void print2()
{
cout<<"基类的西沟函数出现!"<<endl;
}
int getAge(){return 0;}
};
class dog:public mammal
{
public:
dog(int age):itsage(age){};
void print()
{
cout<<"派生类的构造函数出现"<<endl;
}
~dog(){};
void print2()
{
cout<<"派生类的析构函数出现"<<endl;
}
int getAge(){return itsage;}
private:
int itsage;
};
int main()
{
dog adog(5);
mammal ma();
cout<<"the age of the dog is"<<adog.getAge()<<endl;
cout<<ma.print()<<endl;
cout<<ma.print2()<<endl;
cout<<adog.print()<<endl;
cout<<adog.print2()<<endl;
return 0;
}[/size]
该怎么 用空型的 print函数 输出这句话呢。求大神助!!!!!!!!!!
class mammal
{
public:
mammal(){};
void print()
{
cout<<"基类的构造函数出现了"<<endl;
}
~mammal(){};
void print2()
{
cout<<"基类的西沟函数出现!"<<endl;
}
int getAge(){return 0;}
};
class dog:public mammal
{
public:
dog(int age):itsage(age){};
void print()
{
cout<<"派生类的构造函数出现"<<endl;
}
~dog(){};
void print2()
{
cout<<"派生类的析构函数出现"<<endl;
}
int getAge(){return itsage;}
private:
int itsage;
};
int main()
{
dog adog(5);
mammal ma();
cout<<"the age of the dog is"<<adog.getAge()<<endl;
cout<<ma.print()<<endl;
cout<<ma.print2()<<endl;
cout<<adog.print()<<endl;
cout<<adog.print2()<<endl;
return 0;
}[/size]
该怎么 用空型的 print函数 输出这句话呢。求大神助!!!!!!!!!!