请c++高手来阅读一下程序写出运行结果!!!

来源:百度知道 编辑:UC知道 时间:2024/05/04 09:54:19
1、
#include <iostream>
#include <string>
using namespace std;
class Cat
{
public:
string name;
Cat(string na)
{ name = na;
cout<<"new cat name: "<<name<<endl;
}
~Cat()
{ cout<<"delete cat: "<<name<<endl; }
};

int main()
{
Cat c1("Kitty"),c2("Marry");
return 0;
}
2、
#include <iostream.h>
class Cat
{
public:
Cat()
{ cout<<"Constructing cat class "<<endl; }
~Cat()
{ cout<<"Destructing cat class "<<endl; }
};
class Tiger:public Cat
{
public:
Tiger()
{ cout<<"Constructing tiger class"<<endl; }
~Tiger()
{ cout<<"Destructing tiger class"<<endl; }
};
int main()
{
Tiger op;
return 0;

以下运行结果都已经通过VC6.0编译确认

1.
运行结果为:
new cat name: Kitty
new cat name: Marry
delete cat: Marry
delete cat: Kitty

2.
运行结果为:
Constructing cat class
Constructing tiger class
Destructing tiger class
Destructing cat class

3.
运行结果为:
Base: 4,4
Base: 1,2

4.
运行结果为:
real=4.4 image=6.6
real=1.1 image=2.2
real=4.4 image=6.6

5.
运行结果为:
this Cat weights0.9
this Cat weights0.8
2

呵呵,楼上正解...
我就不列答案了.
直接去运行一下嘛

对着结果再研究代码非常好...