#include<iostream.h>
class student
{
int x;
public:
student (int n)
{
cout<<"constructing student."<<endl;
x=n;
}
~student()
{cout<<"destructing student."<<endl;}
void showx()
{cout<<x<<endl;}
};class stu:public student
{
int y;
public:
stu(int n,int m):student(m)
{
cout<<"constructing stu."<<endl;
y=n;
}
~stu()
{cout<<"destructing stu."<<endl;}
void showy()
{cout<<y<<endl;}
};
void main()
{
stu tp(10,20);
tp.showx();
tp.showy();
}
这段代码的运行结果是:
constructing student.
destructing student.
20
10
constructing stu.
destructing stu.为什么不是:
constructing student.
destructing student.
constructing stu.
destructing stu.
20
10 析构还书到底是在何时调用的?
class student
{
int x;
public:
student (int n)
{
cout<<"constructing student."<<endl;
x=n;
}
~student()
{cout<<"destructing student."<<endl;}
void showx()
{cout<<x<<endl;}
};class stu:public student
{
int y;
public:
stu(int n,int m):student(m)
{
cout<<"constructing stu."<<endl;
y=n;
}
~stu()
{cout<<"destructing stu."<<endl;}
void showy()
{cout<<y<<endl;}
};
void main()
{
stu tp(10,20);
tp.showx();
tp.showy();
}
这段代码的运行结果是:
constructing student.
destructing student.
20
10
constructing stu.
destructing stu.为什么不是:
constructing student.
destructing student.
constructing stu.
destructing stu.
20
10 析构还书到底是在何时调用的?
解决方案 »
- CSpinButtonCtrl::GetPos返回值不对
- 对话框中创建视图问题,SDI与Dialog based的区别?
- 如何修改系统菜单的标题
- 高分求助编一个VC小程序
- VC++制作控件,在控件内调用JVM.DLL中的JNI_CreateJavaVM函数失败的问题
- 急救!关于ON_WM_ACTIVEAPP的问题
- 有谁用MS的 ACM(Audio Compression Manager)进行过音频的采集和压缩呀?
- ActiveX 控件,要内嵌在Web页里实现编辑
- 请问怎样把RGB彩色转换成等价的灰了?
- 我有一个动态库,但我不知道函数的参数,怎么才能在程序中调用?
- imap协议哪里有
- 虚拟驱动开发
这段代码的运行结果应该是:
constructing student.
constructing stu.
20
10
destructing stu.
destructing student.